diff --git a/charts/corekubestashcom-backupconfiguration-editor-options/ui/create-ui.yaml b/charts/corekubestashcom-backupconfiguration-editor-options/ui/create-ui.yaml index a164d2978d..52ae7105a3 100644 --- a/charts/corekubestashcom-backupconfiguration-editor-options/ui/create-ui.yaml +++ b/charts/corekubestashcom-backupconfiguration-editor-options/ui/create-ui.yaml @@ -1,237 +1,79 @@ -steps: -- form: - discriminator: - nameSpaceApi: - default: false - type: boolean - elements: - - computed: init - if: returnFalse - type: label-element - - fetch: getNamespaces - label: - text: Namespace - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace +step: +- type: single-step-form + loader: initBundle + elements: + - init: + type: func + value: returnFalse + if: + type: function + name: returnFalse + label: '' + type: label-element + - loader: getNamespaces + label: Namespace + schema: schema/properties/metadata/properties/release/properties/namespace + type: select + - label: Name + schema: schema/properties/metadata/properties/release/properties/name + type: input + - loader: getData|storageRef + label: Storage Ref + schema: schema/properties/spec/properties/backend/properties/storageRef + type: select + - loader: getData|retentionPolicy + label: Retention Policy + schema: schema/properties/spec/properties/backend/properties/retentionPolicy + type: select + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - label: Sessions (JSON format) + schema: schema/properties/spec/properties/sessions + type: textarea + - elements: + - loader: getApiGroup + label: Api Group + validation: + type: required + schema: schema/properties/spec/properties/target/properties/apiGroup type: select - - label: - text: Name - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - fetch: getData|storageRef - label: - text: Storage Ref - schema: - $ref: schema#/properties/spec/properties/backend/properties/storageRef + - loader: getKinds + label: Kind + watcher: + func: setVersion + paths: + - schema/properties/spec/properties/target/properties/kind + validation: + type: required + schema: schema/properties/spec/properties/target/properties/kind type: select - - fetch: getData|retentionPolicy - label: - text: Retention Policy - schema: - $ref: schema#/properties/spec/properties/backend/properties/retentionPolicy + - loader: getNamespaces + label: Namespace + validation: + type: required + schema: schema/properties/spec/properties/target/properties/namespace type: select - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - elements: - - addFormLabel: Session - element: - elements: - - label: - text: Session Name - required: true - schema: - $ref: schema#/items/properties/sessionName - type: input - - label: - text: Schedule - required: true - schema: - $ref: schema#/items/properties/schedule - type: input - - elements: - - inputType: number - label: - text: Security Context - schema: - $ref: schema#/properties/jobTemplate/properties/securityContext - type: input - - fetch: getAddon - label: - text: Name - onChange: clearTasks - required: true - schema: - $ref: schema#/items/properties/addon/properties/name - type: select - - addFormLabel: Task - element: - elements: - - fetch: getTaskNames - label: - text: Name - required: true - schema: - $ref: schema#/items/properties/name - type: select - - label: - text: Params - schema: - $ref: schema#/items/properties/params - type: editor - type: single-step-form - label: - text: Tasks - required: true - resetDependencyPath: /session/addon/name - resetOnChange: true - schema: - $ref: schema#/properties/tasks - tableContents: - - inTableColumn: true - label: - text: Name - path: name - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Params - path: params - type: value - typeOfValue: string - type: single-step-form-array - label: - text: Addon - schema: - $ref: schema#/items/properties/addon - show_label: true - type: single-step-form - - elements: - - fetch: getNamespaces - label: - text: Namespace - required: true - schema: - $ref: schema#/properties/namespace - type: select - - fetch: getEncryptionSecretNames - label: - text: Name - required: true - schema: - $ref: schema#/items/properties/encryptionSecret/properties/name - type: select - label: - text: Encryption Secret - schema: - $ref: schema#/items/properties/encryptionSecret - show_label: true - type: single-step-form - - label: - text: Repo Name - required: true - schema: - $ref: schema#/items/properties/repoName - type: input - type: single-step-form - label: - text: Session - schema: - $ref: schema#/properties/spec/properties/sessions - tableContents: - - inTableColumn: true - label: - text: Repo Name - path: repoName - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Schedule - path: schedule - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Session Name - path: sessionName - type: value - typeOfValue: string - temporaryPath: /session - type: single-step-form-array - type: single-step-form - - elements: - - fetch: getApiGroup - label: - text: Api Group - required: true - schema: - $ref: schema#/properties/spec/properties/target/properties/apiGroup - type: select - - fetch: getKinds - label: - text: Kind - onChange: setVersion - required: true - schema: - $ref: schema#/properties/spec/properties/target/properties/kind - type: select - - fetch: getNamespaces - label: - text: Namespace - required: true - schema: - $ref: schema#/properties/spec/properties/target/properties/namespace - type: select - - fetch: getTargetName - label: - text: Name - required: true - schema: - $ref: schema#/properties/spec/properties/target/properties/name - type: select - hideForm: true - if: showTarget - label: - text: Target - show_label: true - type: single-step-form - type: single-step-form + - loader: getTargetName + label: Name + validation: + type: required + schema: schema/properties/spec/properties/target/properties/name + type: select + if: + type: function + name: showTarget + label: Target + showLabels: true + hideBlock: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/corekubestashcom-backupconfiguration-editor-options/ui/functions.js b/charts/corekubestashcom-backupconfiguration-editor-options/ui/functions.js index 4e6f9975e8..ba564870f7 100644 --- a/charts/corekubestashcom-backupconfiguration-editor-options/ui/functions.js +++ b/charts/corekubestashcom-backupconfiguration-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + let namespaces = [] let appKind = [] let coreKind = [] @@ -6,314 +8,322 @@ let availableKinds = {} let kindToResourceMap = {} let version = '' -function init({ watchDependency, model, getValue, storeGet, axios, setDiscriminatorValue }) { - namespaces = getNamespacesApi({ axios, storeGet, setDiscriminatorValue }) - getKindsApi({ watchDependency, model, getValue, storeGet, axios }) - setDiscriminatorValue('/nameSpaceApi', true) -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('/nameSpaceApi', false) -async function getNamespacesApi({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + async function initBundle() { + namespaces = await getNamespacesApi() + await getKindsApi() + setDiscriminatorValue('/nameSpaceApi', true) + } + + async function getNamespacesApi() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -function getNamespaces({ watchDependency }) { - watchDependency('discriminator#/nameSpaceApi') - return namespaces -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -async function getAddon({ storeGet, axios }) { - const params = storeGet('/route/params') - const { user, cluster } = params - let url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons` - try { - const resp = await axios.get(url) - let addons = [] - resp.data?.items.forEach((item) => { - addons.push(item.metadata.name) - }) - return addons - } catch (e) { - console.log(e) + function getNamespaces() { + // watchDependency('discriminator#/nameSpaceApi') + return namespaces } - return [] -} -async function getTaskNames({ watchDependency, storeGet, axios }) { - watchDependency('temporaryModel#/session/addon/name') - const addon = storeGet('/wizard/temporaryModel/session/addon/name') - const params = storeGet('/route/params') - const { user, cluster } = params - let url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons/${addon}` - if (addon) { + async function getAddon() { + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons` try { const resp = await axios.get(url) - - const backupTasks = resp?.data?.spec?.backupTasks?.map((task) => task.name) || [] - return backupTasks + let addons = [] + resp.data?.items.forEach((item) => { + addons.push(item.metadata.name) + }) + return addons } catch (e) { console.log(e) } + return [] } - return [] -} -function clearTasks({ commit }) { - commit('wizard/temporaryModel$update', { - path: '/session/addon/tasks', - value: [], - force: true, - }) -} + async function getTaskNames() { + // watchDependency('temporaryModel#/session/addon/name') + const addon = storeGet('/wizard/temporaryModel/session/addon/name') + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons/${addon}` + if (addon) { + try { + const resp = await axios.get(url) + + const backupTasks = resp?.data?.spec?.backupTasks?.map((task) => task.name) || [] + return backupTasks + } catch (e) { + console.log(e) + } + } + return [] + } -async function getEncryptionSecretNames({ watchDependency, storeGet, axios }) { - watchDependency('temporaryModel#/session/encryptionSecret/namespace') - const namespace = storeGet('/wizard/temporaryModel/session/encryptionSecret/namespace') - const params = storeGet('/route/params') - const { user, cluster } = params - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - if (namespace) { + function clearTasks() { + commit('wizard/temporaryModel$update', { + path: '/session/addon/tasks', + value: [], + force: true, + }) + } + + async function getEncryptionSecretNames() { + // watchDependency('temporaryModel#/session/encryptionSecret/namespace') + const namespace = storeGet('/wizard/temporaryModel/session/encryptionSecret/namespace') + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + if (namespace) { + try { + const resp = await axios.get(url) + const name = resp?.data?.items?.map((item) => item.metadata?.name) || [] + return name + } catch (e) { + console.log(e) + } + } + return [] + } + + async function getKindsApi() { + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` try { const resp = await axios.get(url) - const name = resp?.data?.items?.map((item) => item.metadata?.name) || [] - return name + + kindToResourceMap['kubedb.com'] = {} + kindToResourceMap['apps'] = {} + kindToResourceMap['core'] = {} + + availableKinds = resp.data + appKind = Object.values(availableKinds['apps']) + .flat() + .map((ele) => { + kindToResourceMap['apps'][ele.Kind] = ele.Resource + return ele.Kind + }) + kubedbKind = Object.values(availableKinds['kubedb.com']) + .flat() + .map((ele) => { + kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource + return ele.Kind + }) + coreKind = Object.values(availableKinds['']) + .flat() + .map((ele) => { + kindToResourceMap['core'][ele.Kind] = ele.Resource + return ele.Kind + }) } catch (e) { console.log(e) } + return [] } - return [] -} -async function getKindsApi({ storeGet, axios }) { - const params = storeGet('/route/params') - const { user, cluster } = params - let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` - try { - const resp = await axios.get(url) + function getKinds() { + // watchDependency(`model#/spec/target/apiGroup`) + const apiGroup = getValue(model, `/spec/target/apiGroup`) - kindToResourceMap['kubedb.com'] = {} - kindToResourceMap['apps'] = {} - kindToResourceMap['core'] = {} + if (apiGroup === 'core') return coreKind + else if (apiGroup === 'apps') return appKind + else return kubedbKind + } - availableKinds = resp.data - appKind = Object.values(availableKinds['apps']) - .flat() - .map((ele) => { - kindToResourceMap['apps'][ele.Kind] = ele.Resource - return ele.Kind - }) - kubedbKind = Object.values(availableKinds['kubedb.com']) - .flat() - .map((ele) => { - kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource - return ele.Kind + function setVersion() { + let apiGroup = getValue(model, `/spec/target/apiGroup`) + const kind = getValue(model, `/spec/target/kind`) + if (apiGroup === 'core') apiGroup = '' + Object.keys(availableKinds[apiGroup]).forEach((vs) => { + availableKinds[apiGroup][vs].forEach((ele) => { + if (ele.Kind === kind) { + version = vs + } }) - coreKind = Object.values(availableKinds['']) - .flat() - .map((ele) => { - kindToResourceMap['core'][ele.Kind] = ele.Resource - return ele.Kind - }) - } catch (e) { - console.log(e) + }) } - return [] -} -function getKinds({ watchDependency, getValue, model }) { - watchDependency(`model#/spec/target/apiGroup`) - const apiGroup = getValue(model, `/spec/target/apiGroup`) + function getApiGroup() { + return ['core', 'apps', 'kubedb.com'] + } - if (apiGroup === 'core') return coreKind - else if (apiGroup === 'apps') return appKind - else return kubedbKind -} + async function getTargetName() { + // watchDependency('model#/spec/target/apiGroup') + // watchDependency('model#/spec/target/namespace') + // watchDependency('model#/spec/target/kind') + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const namespace = getValue(model, `/spec/target/namespace`) + const resource = getResourceName() + const params = storeGet('/route/params') + const { user, cluster } = params -function setVersion({ getValue, model }) { - const apiGroup = getValue(model, `/spec/target/apiGroup`) - const kind = getValue(model, `/spec/target/kind`) - if (apiGroup === 'core') apiGroup = '' - Object.keys(availableKinds[apiGroup]).forEach((vs) => { - availableKinds[apiGroup][vs].forEach((ele) => { - if (ele.Kind === kind) { - version = vs + const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` + if (apiGroup && version && resource && namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + const options = items.map((ele) => { + return ele.metadata.name + }) + return options + } catch (e) { + console.log(e) } - }) - }) -} + } + return [] + } -function getApiGroup() { - return ['core', 'apps', 'kubedb.com'] -} + function getResourceName() { + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const kind = getValue(model, `/spec/target/kind`) + if (!kind || !apiGroup) return '' + return kindToResourceMap[apiGroup][kind] + } -async function getTargetName({ watchDependency, getValue, model, axios, storeGet }) { - watchDependency('model#/spec/target/apiGroup') - watchDependency('model#/spec/target/namespace') - watchDependency('model#/spec/target/kind') - const apiGroup = getValue(model, `/spec/target/apiGroup`) - const namespace = getValue(model, `/spec/target/namespace`) - const resource = getResourceName({ getValue, model }) - const params = storeGet('/route/params') - const { user, cluster } = params + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` - if (apiGroup && version && resource && namespace) { try { - const resp = await axios.get(url) - const items = resp.data?.items - const options = items.map((ele) => { - return ele.metadata.name - }) - return options + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() } catch (e) { console.log(e) } - } - return [] -} - -function getResourceName({ getValue, model }) { - const apiGroup = getValue(model, `/spec/target/apiGroup`) - const kind = getValue(model, `/spec/target/kind`) - if (!kind || !apiGroup) return '' - return kindToResourceMap[apiGroup][kind] -} - -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } } -} -async function getData({ axios, route }, type) { - const user = route.params.user - const cluster = route.params.cluster - url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/${ - type === 'retentionPolicy' ? 'retentionpolicies' : 'backupstorages' - }` - try { - const data = await axios.get(url) - const items = data.data?.items || [] - const options = items.map((item) => { - return { - text: `${item.metadata.namespace}/${item.metadata.name}`, - value: { name: item.metadata.name, namespace: item.metadata.namespace }, - } - }) - return options || [] - } catch (e) { - console.log(e) - return [] + async function getData(ctx, type) { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/${ + type === 'retentionPolicy' ? 'retentionpolicies' : 'backupstorages' + }` + try { + const data = await axios.get(url) + const items = data.data?.items || [] + const options = items.map((item) => { + return { + text: `${item.metadata.namespace}/${item.metadata.name}`, + value: { name: item.metadata.name, namespace: item.metadata.namespace }, + } + }) + return options || [] + } catch (e) { + console.log(e) + return [] + } } -} -function showTarget({ route, commit, storeGet }) { - const params = route.params || {} - const { group, name } = params - const query = route.query || {} - const namespace = query.namespace || '' - const kind = storeGet('/resource/layout/result/resource/kind') || '' + function showTarget() { + const params = storeGet('/route/params') || {} + const { group, name } = params + const namespace = storeGet('/route/query/namespace') || '' + const kind = storeGet('/resource/layout/result/resource/kind') || '' - if (group === 'kubedb.com') { - const target = { - apiGroup: 'kubedb.com', - kind: kind, - namespace: namespace, - name: name, + if (group === 'kubedb.com') { + const target = { + apiGroup: 'kubedb.com', + kind: kind, + namespace: namespace, + name: name, + } + commit('wizard/model$update', { + path: '/spec/target', + value: target, + force: true, + }) } - commit('wizard/model$update', { - path: '/spec/target', - value: target, - force: true, - }) + return group !== 'kubedb.com' } - return group !== 'kubedb.com' -} -function returnFalse() { - return false -} + function returnFalse() { + return false + } -return { - isRancherManaged, - setVersion, - getTargetName, - getApiGroup, - getEncryptionSecretNames, - getKinds, - getTaskNames, - getAddon, - init, - returnFalse, - fetchJsons, - getNamespaces, - clearTasks, - showTarget, - getData, + return { + clearTasks, + fetchJsons, + getAddon, + getApiGroup, + getData, + getEncryptionSecretNames, + getKinds, + getNamespaces, + getTargetName, + getTaskNames, + initBundle, + isRancherManaged, + returnFalse, + setVersion, + showTarget, + } } diff --git a/charts/corekubestashcom-backupconfiguration-editor-options/ui/old.create-ui.yaml b/charts/corekubestashcom-backupconfiguration-editor-options/ui/old.create-ui.yaml new file mode 100644 index 0000000000..a164d2978d --- /dev/null +++ b/charts/corekubestashcom-backupconfiguration-editor-options/ui/old.create-ui.yaml @@ -0,0 +1,237 @@ +steps: +- form: + discriminator: + nameSpaceApi: + default: false + type: boolean + elements: + - computed: init + if: returnFalse + type: label-element + - fetch: getNamespaces + label: + text: Namespace + schema: + $ref: schema#/properties/metadata/properties/release/properties/namespace + type: select + - label: + text: Name + schema: + $ref: schema#/properties/metadata/properties/release/properties/name + type: input + - fetch: getData|storageRef + label: + text: Storage Ref + schema: + $ref: schema#/properties/spec/properties/backend/properties/storageRef + type: select + - fetch: getData|retentionPolicy + label: + text: Retention Policy + schema: + $ref: schema#/properties/spec/properties/backend/properties/retentionPolicy + type: select + - elements: + - isArray: true + keys: + label: + text: labels.labels.key + label: + text: labels.labels.label + schema: + $ref: schema#/properties/spec/properties/labels + type: key-value-input-form + values: + label: + text: labels.labels.value + schema: + $ref: schema#/properties/spec/properties/labels/additionalProperties + type: input + - isArray: true + keys: + label: + text: labels.annotations.key + label: + text: labels.annotations.label + schema: + $ref: schema#/properties/spec/properties/annotations + type: key-value-input-form + values: + label: + text: labels.annotations.value + schema: + $ref: schema#/properties/spec/properties/annotations/additionalProperties + type: input + hideForm: true + label: + text: Labels & Annotations + show_label: true + type: single-step-form + - elements: + - addFormLabel: Session + element: + elements: + - label: + text: Session Name + required: true + schema: + $ref: schema#/items/properties/sessionName + type: input + - label: + text: Schedule + required: true + schema: + $ref: schema#/items/properties/schedule + type: input + - elements: + - inputType: number + label: + text: Security Context + schema: + $ref: schema#/properties/jobTemplate/properties/securityContext + type: input + - fetch: getAddon + label: + text: Name + onChange: clearTasks + required: true + schema: + $ref: schema#/items/properties/addon/properties/name + type: select + - addFormLabel: Task + element: + elements: + - fetch: getTaskNames + label: + text: Name + required: true + schema: + $ref: schema#/items/properties/name + type: select + - label: + text: Params + schema: + $ref: schema#/items/properties/params + type: editor + type: single-step-form + label: + text: Tasks + required: true + resetDependencyPath: /session/addon/name + resetOnChange: true + schema: + $ref: schema#/properties/tasks + tableContents: + - inTableColumn: true + label: + text: Name + path: name + type: value + typeOfValue: string + - inTableColumn: true + label: + text: Params + path: params + type: value + typeOfValue: string + type: single-step-form-array + label: + text: Addon + schema: + $ref: schema#/items/properties/addon + show_label: true + type: single-step-form + - elements: + - fetch: getNamespaces + label: + text: Namespace + required: true + schema: + $ref: schema#/properties/namespace + type: select + - fetch: getEncryptionSecretNames + label: + text: Name + required: true + schema: + $ref: schema#/items/properties/encryptionSecret/properties/name + type: select + label: + text: Encryption Secret + schema: + $ref: schema#/items/properties/encryptionSecret + show_label: true + type: single-step-form + - label: + text: Repo Name + required: true + schema: + $ref: schema#/items/properties/repoName + type: input + type: single-step-form + label: + text: Session + schema: + $ref: schema#/properties/spec/properties/sessions + tableContents: + - inTableColumn: true + label: + text: Repo Name + path: repoName + type: value + typeOfValue: string + - inTableColumn: true + label: + text: Schedule + path: schedule + type: value + typeOfValue: string + - inTableColumn: true + label: + text: Session Name + path: sessionName + type: value + typeOfValue: string + temporaryPath: /session + type: single-step-form-array + type: single-step-form + - elements: + - fetch: getApiGroup + label: + text: Api Group + required: true + schema: + $ref: schema#/properties/spec/properties/target/properties/apiGroup + type: select + - fetch: getKinds + label: + text: Kind + onChange: setVersion + required: true + schema: + $ref: schema#/properties/spec/properties/target/properties/kind + type: select + - fetch: getNamespaces + label: + text: Namespace + required: true + schema: + $ref: schema#/properties/spec/properties/target/properties/namespace + type: select + - fetch: getTargetName + label: + text: Name + required: true + schema: + $ref: schema#/properties/spec/properties/target/properties/name + type: select + hideForm: true + if: showTarget + label: + text: Target + show_label: true + type: single-step-form + type: single-step-form + id: options + title: steps.0.label +type: multi-step-form diff --git a/charts/corekubestashcom-backupconfiguration-editor-options/ui/old.functions.js b/charts/corekubestashcom-backupconfiguration-editor-options/ui/old.functions.js new file mode 100644 index 0000000000..4e6f9975e8 --- /dev/null +++ b/charts/corekubestashcom-backupconfiguration-editor-options/ui/old.functions.js @@ -0,0 +1,319 @@ +let namespaces = [] +let appKind = [] +let coreKind = [] +let kubedbKind = [] +let availableKinds = {} +let kindToResourceMap = {} +let version = '' + +function init({ watchDependency, model, getValue, storeGet, axios, setDiscriminatorValue }) { + namespaces = getNamespacesApi({ axios, storeGet, setDiscriminatorValue }) + getKindsApi({ watchDependency, model, getValue, storeGet, axios }) + setDiscriminatorValue('/nameSpaceApi', true) +} + +async function getNamespacesApi({ axios, storeGet }) { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] +} + +function isRancherManaged({ storeGet }) { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found +} + +function getNamespaces({ watchDependency }) { + watchDependency('discriminator#/nameSpaceApi') + return namespaces +} + +async function getAddon({ storeGet, axios }) { + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons` + try { + const resp = await axios.get(url) + let addons = [] + resp.data?.items.forEach((item) => { + addons.push(item.metadata.name) + }) + return addons + } catch (e) { + console.log(e) + } + return [] +} + +async function getTaskNames({ watchDependency, storeGet, axios }) { + watchDependency('temporaryModel#/session/addon/name') + const addon = storeGet('/wizard/temporaryModel/session/addon/name') + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons/${addon}` + if (addon) { + try { + const resp = await axios.get(url) + + const backupTasks = resp?.data?.spec?.backupTasks?.map((task) => task.name) || [] + return backupTasks + } catch (e) { + console.log(e) + } + } + return [] +} + +function clearTasks({ commit }) { + commit('wizard/temporaryModel$update', { + path: '/session/addon/tasks', + value: [], + force: true, + }) +} + +async function getEncryptionSecretNames({ watchDependency, storeGet, axios }) { + watchDependency('temporaryModel#/session/encryptionSecret/namespace') + const namespace = storeGet('/wizard/temporaryModel/session/encryptionSecret/namespace') + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + if (namespace) { + try { + const resp = await axios.get(url) + const name = resp?.data?.items?.map((item) => item.metadata?.name) || [] + return name + } catch (e) { + console.log(e) + } + } + return [] +} + +async function getKindsApi({ storeGet, axios }) { + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` + try { + const resp = await axios.get(url) + + kindToResourceMap['kubedb.com'] = {} + kindToResourceMap['apps'] = {} + kindToResourceMap['core'] = {} + + availableKinds = resp.data + appKind = Object.values(availableKinds['apps']) + .flat() + .map((ele) => { + kindToResourceMap['apps'][ele.Kind] = ele.Resource + return ele.Kind + }) + kubedbKind = Object.values(availableKinds['kubedb.com']) + .flat() + .map((ele) => { + kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource + return ele.Kind + }) + coreKind = Object.values(availableKinds['']) + .flat() + .map((ele) => { + kindToResourceMap['core'][ele.Kind] = ele.Resource + return ele.Kind + }) + } catch (e) { + console.log(e) + } + return [] +} + +function getKinds({ watchDependency, getValue, model }) { + watchDependency(`model#/spec/target/apiGroup`) + const apiGroup = getValue(model, `/spec/target/apiGroup`) + + if (apiGroup === 'core') return coreKind + else if (apiGroup === 'apps') return appKind + else return kubedbKind +} + +function setVersion({ getValue, model }) { + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const kind = getValue(model, `/spec/target/kind`) + if (apiGroup === 'core') apiGroup = '' + Object.keys(availableKinds[apiGroup]).forEach((vs) => { + availableKinds[apiGroup][vs].forEach((ele) => { + if (ele.Kind === kind) { + version = vs + } + }) + }) +} + +function getApiGroup() { + return ['core', 'apps', 'kubedb.com'] +} + +async function getTargetName({ watchDependency, getValue, model, axios, storeGet }) { + watchDependency('model#/spec/target/apiGroup') + watchDependency('model#/spec/target/namespace') + watchDependency('model#/spec/target/kind') + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const namespace = getValue(model, `/spec/target/namespace`) + const resource = getResourceName({ getValue, model }) + const params = storeGet('/route/params') + const { user, cluster } = params + + const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` + if (apiGroup && version && resource && namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + const options = items.map((ele) => { + return ele.metadata.name + }) + return options + } catch (e) { + console.log(e) + } + } + return [] +} + +function getResourceName({ getValue, model }) { + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const kind = getValue(model, `/spec/target/kind`) + if (!kind || !apiGroup) return '' + return kindToResourceMap[apiGroup][kind] +} + +async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } +} + +async function getData({ axios, route }, type) { + const user = route.params.user + const cluster = route.params.cluster + url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/${ + type === 'retentionPolicy' ? 'retentionpolicies' : 'backupstorages' + }` + try { + const data = await axios.get(url) + const items = data.data?.items || [] + const options = items.map((item) => { + return { + text: `${item.metadata.namespace}/${item.metadata.name}`, + value: { name: item.metadata.name, namespace: item.metadata.namespace }, + } + }) + return options || [] + } catch (e) { + console.log(e) + return [] + } +} + +function showTarget({ route, commit, storeGet }) { + const params = route.params || {} + const { group, name } = params + const query = route.query || {} + const namespace = query.namespace || '' + const kind = storeGet('/resource/layout/result/resource/kind') || '' + + if (group === 'kubedb.com') { + const target = { + apiGroup: 'kubedb.com', + kind: kind, + namespace: namespace, + name: name, + } + commit('wizard/model$update', { + path: '/spec/target', + value: target, + force: true, + }) + } + return group !== 'kubedb.com' +} + +function returnFalse() { + return false +} + +return { + isRancherManaged, + setVersion, + getTargetName, + getApiGroup, + getEncryptionSecretNames, + getKinds, + getTaskNames, + getAddon, + init, + returnFalse, + fetchJsons, + getNamespaces, + clearTasks, + showTarget, + getData, +} diff --git a/charts/corekubestashcom-backupsession-editor-options/ui/create-ui.yaml b/charts/corekubestashcom-backupsession-editor-options/ui/create-ui.yaml index 59cb60832e..cf7447fb1b 100644 --- a/charts/corekubestashcom-backupsession-editor-options/ui/create-ui.yaml +++ b/charts/corekubestashcom-backupsession-editor-options/ui/create-ui.yaml @@ -1,88 +1,62 @@ -steps: -- form: +step: +- type: single-step-form + elements: + - loader: fetchNamespaces + hasGroup: isRancherManaged + label: Namespace + schema: schema/properties/metadata/properties/release/properties/namespace + type: select + - type: block-layout + label: Labels & Annotations + showLabels: true elements: - - fetch: fetchNamespaces - hasGroup: isRancherManaged - label: - text: labels.namespace - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - - label: - text: Invoker Kind - options: - - text: Backup Configurations - value: BackupConfiguration - - text: Backup Blueprints - value: BackupBlueprint - schema: - $ref: schema#/properties/spec/properties/invoker/properties/kind - type: select - - fetch: fetchInvokerName - label: - text: Invoker Name - onChange: initName - schema: - $ref: schema#/properties/spec/properties/invoker/properties/name - type: select - - fetch: fetchSessions - label: - text: Session - onChange: initName - schema: - $ref: schema#/properties/spec/properties/session - type: select - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/backupTimeout - type: select - type: single-step-form + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + - label: Invoker Kind + options: + - text: Backup Configurations + value: BackupConfiguration + - text: Backup Blueprints + value: BackupBlueprint + schema: schema/properties/spec/properties/invoker/properties/kind + type: select + - loader: fetchInvokerName + label: Invoker Name + watcher: + func: initName + paths: + - schema/properties/spec/properties/invoker/properties/name + schema: schema/properties/spec/properties/invoker/properties/name + type: select + - loader: fetchSessions + label: Session + watcher: + func: initName + paths: + - schema/properties/spec/properties/session + schema: schema/properties/spec/properties/session + type: select + - label: Timeout + options: + - text: 5 minutes + value: 5m + - text: 10 minutes + value: 10m + - text: 30 minutes + value: 30m + - text: 1 hour + value: 1h + - text: 2 hours + value: 2h + - text: 5 hours + value: 5h + - text: 10 hours + value: 10h + schema: schema/properties/spec/properties/backupTimeout + type: select id: options - title: steps.0.label type: multi-step-form diff --git a/charts/corekubestashcom-backupsession-editor-options/ui/functions.js b/charts/corekubestashcom-backupsession-editor-options/ui/functions.js index 97487a939c..e43d10cea3 100644 --- a/charts/corekubestashcom-backupsession-editor-options/ui/functions.js +++ b/charts/corekubestashcom-backupsession-editor-options/ui/functions.js @@ -1,112 +1,121 @@ -let invokerData = [] +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} -function initName({ model, getValue, commit }) { - const invoker = getValue(model, '/spec/invoker/name') || '' - const session = getValue(model, '/spec/session') || '' - let name = '' - if (invoker && session) name = `${invoker}-${session}-${Date.now()}` - else name = '' - commit('wizard/model$update', { - path: '/metadata/release/name', - value: name, - force: true, - }) +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) - const found = invokerData.find((item) => item.metadata.name === invoker) - const uid = found ? found.metadata?.uid : '' - commit('wizard/model$update', { - path: '/spec/ownerUID', - value: uid, - force: true, - }) -} + let invokerData = [] + + function initName() { + const invoker = getValue(model, '/spec/invoker/name') || '' + const session = getValue(model, '/spec/session') || '' + let name = '' + if (invoker && session) name = `${invoker}-${session}-${Date.now()}` + else name = '' + commit('wizard/model$update', { + path: '/metadata/release/name', + value: name, + force: true, + }) + + const found = invokerData.find((item) => item.metadata.name === invoker) + const uid = found ? found.metadata?.uid : '' + commit('wizard/model$update', { + path: '/spec/ownerUID', + value: uid, + force: true, + }) + } -async function fetchNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + async function fetchNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -async function fetchInvokerName({ getValue, model, watchDependency, axios, storeGet }) { - watchDependency('model#/spec/invoker/kind') - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') || '' - const kind = getValue(model, '/spec/invoker/kind') || '' - const user = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const core = 'core.kubestash.com' - const version = 'v1alpha1' - const suffix = kind === 'BackupConfiguration' ? 'backupconfigurations' : 'backupblueprints' - try { - if (namespace && kind) { - const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/${suffix}` - const resp = await axios.get(url) - invokerData = resp.data.items - const names = resp.data.items.map((item) => { - const name = item.metadata?.name - return name - }) - return names + async function fetchInvokerName() { + // watchDependency('model#/spec/invoker/kind') + // watchDependency('model#/metadata/release/namespace') + const namespace = getValue(model, '/metadata/release/namespace') || '' + const kind = getValue(model, '/spec/invoker/kind') || '' + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const core = 'core.kubestash.com' + const version = 'v1alpha1' + const suffix = kind === 'BackupConfiguration' ? 'backupconfigurations' : 'backupblueprints' + try { + if (namespace && kind) { + const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/${suffix}` + const resp = await axios.get(url) + invokerData = resp.data.items + const names = resp.data.items.map((item) => { + const name = item.metadata?.name + return name + }) + return names + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function fetchSessions({ getValue, model, watchDependency }) { - watchDependency('model#/spec/invoker/name') - const invokerName = getValue(model, '/spec/invoker/name') || '' - const found = invokerData.find((item) => item.metadata.name === invokerName) - if (found) return found.spec?.sessions.map((item) => item.name) - return [] -} + function fetchSessions() { + // watchDependency('model#/spec/invoker/name') + const invokerName = getValue(model, '/spec/invoker/name') || '' + const found = invokerData.find((item) => item.metadata.name === invokerName) + if (found) return found.spec?.sessions.map((item) => item.name) + return [] + } -return { - isRancherManaged, - initName, - fetchNamespaces, - fetchInvokerName, - fetchSessions, + return { + isRancherManaged, + initName, + fetchNamespaces, + fetchInvokerName, + fetchSessions, + } } diff --git a/charts/corekubestashcom-backupsession-editor-options/ui/old.create-ui.yaml b/charts/corekubestashcom-backupsession-editor-options/ui/old.create-ui.yaml new file mode 100644 index 0000000000..59cb60832e --- /dev/null +++ b/charts/corekubestashcom-backupsession-editor-options/ui/old.create-ui.yaml @@ -0,0 +1,88 @@ +steps: +- form: + elements: + - fetch: fetchNamespaces + hasGroup: isRancherManaged + label: + text: labels.namespace + schema: + $ref: schema#/properties/metadata/properties/release/properties/namespace + type: select + - isArray: true + keys: + label: + text: labels.labels.key + label: + text: labels.labels.label + schema: + $ref: schema#/properties/spec/properties/labels + type: key-value-input-form + values: + label: + text: labels.labels.value + schema: + $ref: schema#/properties/spec/properties/labels/additionalProperties + type: input + - isArray: true + keys: + label: + text: labels.annotations.key + label: + text: labels.annotations.label + schema: + $ref: schema#/properties/spec/properties/annotations + type: key-value-input-form + values: + label: + text: labels.annotations.value + schema: + $ref: schema#/properties/spec/properties/annotations/additionalProperties + type: input + - label: + text: Invoker Kind + options: + - text: Backup Configurations + value: BackupConfiguration + - text: Backup Blueprints + value: BackupBlueprint + schema: + $ref: schema#/properties/spec/properties/invoker/properties/kind + type: select + - fetch: fetchInvokerName + label: + text: Invoker Name + onChange: initName + schema: + $ref: schema#/properties/spec/properties/invoker/properties/name + type: select + - fetch: fetchSessions + label: + text: Session + onChange: initName + schema: + $ref: schema#/properties/spec/properties/session + type: select + - label: + text: labels.timeout + options: + - text: 5 minutes + value: 5m + - text: 10 minutes + value: 10m + - text: 30 minutes + value: 30m + - text: 1 hour + value: 1h + - text: 2 hours + value: 2h + - text: 5 hours + value: 5h + - text: 10 hours + value: 10h + schema: + $ref: schema#/properties/spec/properties/backupTimeout + type: select + type: single-step-form + id: options + title: steps.0.label +type: multi-step-form diff --git a/charts/corekubestashcom-backupsession-editor-options/ui/old.functions.js b/charts/corekubestashcom-backupsession-editor-options/ui/old.functions.js new file mode 100644 index 0000000000..97487a939c --- /dev/null +++ b/charts/corekubestashcom-backupsession-editor-options/ui/old.functions.js @@ -0,0 +1,112 @@ +let invokerData = [] + +function initName({ model, getValue, commit }) { + const invoker = getValue(model, '/spec/invoker/name') || '' + const session = getValue(model, '/spec/session') || '' + let name = '' + if (invoker && session) name = `${invoker}-${session}-${Date.now()}` + else name = '' + commit('wizard/model$update', { + path: '/metadata/release/name', + value: name, + force: true, + }) + + const found = invokerData.find((item) => item.metadata.name === invoker) + const uid = found ? found.metadata?.uid : '' + commit('wizard/model$update', { + path: '/spec/ownerUID', + value: uid, + force: true, + }) +} + +async function fetchNamespaces({ axios, storeGet }) { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] +} + +function isRancherManaged({ storeGet }) { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found +} + +async function fetchInvokerName({ getValue, model, watchDependency, axios, storeGet }) { + watchDependency('model#/spec/invoker/kind') + watchDependency('model#/metadata/release/namespace') + const namespace = getValue(model, '/metadata/release/namespace') || '' + const kind = getValue(model, '/spec/invoker/kind') || '' + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const core = 'core.kubestash.com' + const version = 'v1alpha1' + const suffix = kind === 'BackupConfiguration' ? 'backupconfigurations' : 'backupblueprints' + try { + if (namespace && kind) { + const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/${suffix}` + const resp = await axios.get(url) + invokerData = resp.data.items + const names = resp.data.items.map((item) => { + const name = item.metadata?.name + return name + }) + return names + } + } catch (e) { + console.log(e) + } + return [] +} + +function fetchSessions({ getValue, model, watchDependency }) { + watchDependency('model#/spec/invoker/name') + const invokerName = getValue(model, '/spec/invoker/name') || '' + const found = invokerData.find((item) => item.metadata.name === invokerName) + if (found) return found.spec?.sessions.map((item) => item.name) + return [] +} + +return { + isRancherManaged, + initName, + fetchNamespaces, + fetchInvokerName, + fetchSessions, +} diff --git a/charts/corekubestashcom-backupsession-editor/ui/create-ui.yaml b/charts/corekubestashcom-backupsession-editor/ui/create-ui.yaml index 15217e6c70..80cea628cf 100644 --- a/charts/corekubestashcom-backupsession-editor/ui/create-ui.yaml +++ b/charts/corekubestashcom-backupsession-editor/ui/create-ui.yaml @@ -1,36 +1,38 @@ -steps: -- form: - discriminator: - backup: - type: string - initApi: - default: false - type: boolean - selectedSessions: - type: Array - elements: - - computed: init - if: returnFalse - type: label-element - - fetch: getOptions - if: isApiResolved - label: - text: Select Backup - onChange: clearModel - required: true - schema: - $ref: discriminator#/backup - type: select - - fetch: getSessionOptions - if: isBackupSelected - label: - text: Select Sessions - onChange: buildCommand - required: true - schema: - $ref: discriminator#/selectedSessions - type: multiselect - type: single-step-form - id: basic - title: steps.0.label type: multi-step-form +step: + - type: single-step-form + id: basic + # label: Basic Information + loader: init + elements: + - type: select + label: Select Backup + schema: temp/properties/backup + validation: + type: required + if: + type: function + name: isApiResolved + loader: getOptions + watcher: + func: clearModel + paths: + - temp/properties/backup + - type: select + multiple: true + label: Select Sessions + schema: temp/properties/selectedSessions + refresh: true + validation: + type: required + if: + type: function + name: isBackupSelected + loader: + name: getSessionOptions + watchPaths: + - temp/properties/backup + watcher: + func: buildCommand + paths: + - temp/properties/selectedSessions diff --git a/charts/corekubestashcom-backupsession-editor/ui/functions.js b/charts/corekubestashcom-backupsession-editor/ui/functions.js index a65d7c4659..a892949faa 100644 --- a/charts/corekubestashcom-backupsession-editor/ui/functions.js +++ b/charts/corekubestashcom-backupsession-editor/ui/functions.js @@ -1,97 +1,111 @@ -let options = [] -let backups = [] -let backupName = '' -let backupNamespace = '' - -async function init({ storeGet, axios, setDiscriminatorValue, commit }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') - const name = storeGet('/route/params/name') - const url = `/clusters/${owner}/${cluster}/proxy/core.kubestash.com/v1alpha1/namespaces/${namespace}/backupconfigurations` - - try { - const resp = await axios.get(url) - const items = resp.data.items - - backups = items - items.forEach((ele) => { - if (ele.spec?.target?.name === name && ele.spec?.target?.namespace === namespace) { - const tx = `${ele.metadata.namespace}/${ele.metadata.name}` - options.push({ text: tx, value: ele.metadata.name }) +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('backup', '') + setDiscriminatorValue('initApi', false) + setDiscriminatorValue('selectedSessions', []) + + let options = [] + let backups = [] + let backupName = '' + let backupNamespace = '' + + // **************** common functions **************** + + async function init() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') + const name = storeGet('/route/params/name') + const url = `/clusters/${owner}/${cluster}/proxy/core.kubestash.com/v1alpha1/namespaces/${namespace}/backupconfigurations` + + try { + const resp = await axios.get(url) + const items = resp.data.items + + backups = items + items.forEach((ele) => { + if (ele.spec?.target?.name === name && ele.spec?.target?.namespace === namespace) { + const tx = `${ele.metadata.namespace}/${ele.metadata.name}` + options.push({ text: tx, value: ele.metadata.name }) + } + }) + } catch (e) { + console.log(e) + } + setDiscriminatorValue('/initApi', true) + } + + function getOptions() { + return options + } + + function getSessionOptions() { + const backup = getValue(discriminator, '/backup') + let sessions = [] + backups?.forEach((ele) => { + if (ele.metadata.name === backup) { + backupName = ele.metadata.name + backupNamespace = ele.metadata.namespace + sessions = ele.spec.sessions } }) - } catch (e) { - console.log(e) + const optionsArray = sessions?.map((ele) => ele.name) + return optionsArray } - setDiscriminatorValue('/initApi', true) -} - -function getOptions() { - return options -} -function getSessionOptions({ getValue, discriminator, watchDependency }) { - watchDependency('discriminator#/backup') - const backup = getValue(discriminator, '/backup') - let sessions = [] - backups?.forEach((ele) => { - if (ele.metadata.name === backup) { - backupName = ele.metadata.name - backupNamespace = ele.metadata.namespace - sessions = ele.spec.sessions - } - }) - const optionsArray = sessions?.map((ele) => ele.name) - return optionsArray -} + function returnFalse() { + return false + } -function returnFalse() { - return false -} + function isApiResolved() { + const initApi = getValue(discriminator, '/initApi') + return initApi + } -function isApiResolved({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/initApi') - const initApi = getValue(discriminator, '/initApi') - return initApi -} + function isBackupSelected() { + const backup = getValue(discriminator, '/backup') + return backup + } -function isBackupSelected({ getValue, discriminator, watchDependency }) { - watchDependency('discriminator#/backup') - const backup = getValue(discriminator, '/backup') - return backup -} + function buildCommand() { + const sessions = getValue(discriminator, '/selectedSessions') + let generatedCommand = `trigger ${backupName} -n ${backupNamespace}` + sessions?.forEach((ele) => { + generatedCommand += ` --sessions ${ele}` + }) -function buildCommand({ getValue, discriminator, commit }) { - const sessions = getValue(discriminator, '/selectedSessions') - let generatedCommand = `kubectl-kubestash trigger ${backupName} -n ${backupNamespace}` - sessions?.forEach((ele) => { - generatedCommand += ` --sessions ${ele}` - }) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupSession/', - value: generatedCommand, - force: true, - }) -} + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupSession/', + value: generatedCommand, + force: true, + }) + } -function clearModel({ commit, setDiscriminatorValue }) { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupSession/', - value: '', - force: true, - }) - setDiscriminatorValue('/selectedSessions', []) -} + function clearModel() { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupSession/', + value: '', + force: true, + }) + setDiscriminatorValue('/selectedSessions', []) + } -return { - clearModel, - getSessionOptions, - isBackupSelected, - buildCommand, - isApiResolved, - getOptions, - init, - returnFalse, + return { + clearModel, + getSessionOptions, + isBackupSelected, + buildCommand, + isApiResolved, + getOptions, + init, + returnFalse, + } } diff --git a/charts/corekubestashcom-restoresession-editor-options/ui/create-ui.yaml b/charts/corekubestashcom-restoresession-editor-options/ui/create-ui.yaml index 8daa59492d..e3ddeac890 100644 --- a/charts/corekubestashcom-restoresession-editor-options/ui/create-ui.yaml +++ b/charts/corekubestashcom-restoresession-editor-options/ui/create-ui.yaml @@ -1,125 +1,102 @@ -steps: -- form: - elements: - - discriminator: - database: - default: {} - type: object - nameSpaceApi: - default: false - type: boolean +type: multi-step-form +step: +- type: single-step-form + id: options + loader: init + elements: + - type: select + label: Select Namespace + schema: schema/properties/metadata/properties/release/properties/namespace + hasGroup: isRancherManaged + if: + type: function + name: isConsole + loader: + name: fetchNamespaces + watchPaths: + - temp/properties/nameSpaceApi + - type: input + label: Name + schema: schema/properties/metadata/properties/release/properties/name + if: + type: function + name: isConsole + - type: block-layout + showLabels: false + loader: initMetadata + elements: + - type: select + label: Repository + disableUnselect: true + schema: temp/properties/repository + refresh: true + validation: + type: required + loader: getRepositories + - type: select + disableUnselect: true + label: Snapshot + refresh: true + schema: schema/properties/spec/properties/dataSource/properties/snapshot + loader: + name: getSnapshots + watchPaths: + - temp/properties/repository + watcher: + func: onRepoChange + paths: + - temp/properties/repository + - type: select + label: Name + refresh: true + schema: schema/properties/spec/properties/addon/properties/name + if: + type: function + name: isConsole + loader: getAddons + - type: textarea + label: Additional Parameters + schema: temp/properties/params + watcher: + func: onParameterChange + paths: + - temp/properties/params + - type: block-layout + showLabels: true + hideBlock: true + label: Target + if: + type: function + name: isConsole elements: - - fetch: fetchNamespaces + - type: select + label: Api Group + schema: schema/properties/spec/properties/target/properties/apiGroup + loader: getApiGroup + - type: select + label: Kind + schema: schema/properties/spec/properties/target/properties/kind + loader: getKinds + watcher: + func: setVersion + paths: + - schema/properties/spec/properties/target/properties/kind + - schema/properties/spec/properties/target/properties/apiGroup + - type: select + label: Namespace + schema: schema/properties/spec/properties/target/properties/namespace + loader: fetchNamespaces hasGroup: isRancherManaged - if: isConsole - label: - text: Select Namespace - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - computed: init - if: returnFalse - type: input - - if: isConsole - label: - text: labels.name - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - elements: - - computed: initMetadata - if: returnFalse - type: input - - discriminator: - repository: - type: object - elements: - - disableUnselect: true - fetch: getRepositories - label: - text: Repository - onChange: onRepoChange - refresh: true - required: true - schema: - $ref: discriminator#/properties/repository - type: select - - disableUnselect: true - fetch: getSnapshots - label: - text: labels.dataSource.snapshot - refresh: true - schema: - $ref: schema#/properties/spec/properties/dataSource/properties/snapshot - type: select - schema: - $ref: schema#/properties/spec/properties/dataSource - type: single-step-form - - discriminator: - params: - default: "" - type: string - elements: - - fetch: getAddons - if: isConsole - label: - text: labels.name - refresh: true - schema: - $ref: schema#/properties/spec/properties/addon/properties/name - type: select - - label: - text: Additional Parameters - onChange: onParameterChange - schema: - $ref: discriminator#/properties/params - type: textarea - - computed: setSecurityContext - if: returnFalse - type: input - schema: - $ref: schema#/properties/spec/properties/addon - type: single-step-form - - elements: - - fetch: getApiGroup - label: - text: Api Group - schema: - $ref: schema#/properties/spec/properties/target/properties/apiGroup - type: select - - fetch: getKinds - label: - text: Kind - onChange: setVersion - schema: - $ref: schema#/properties/spec/properties/target/properties/kind - type: select - - fetch: fetchNamespaces - hasGroup: isRancherManaged - label: - text: Namespace - schema: - $ref: schema#/properties/spec/properties/target/properties/namespace - type: select - - fetch: getTargetName - label: - text: Name - schema: - $ref: schema#/properties/spec/properties/target/properties/name - type: select - hideForm: true - if: isConsole - label: - text: Target - schema: - $ref: schema#/properties/spec/properties/target - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/spec - type: single-step-form - type: single-step-form - type: single-step-form - id: options - title: steps.0.label -type: multi-step-form + watcher: + func: fetchNamespaces + paths: + - temp/properties/nameSpaceApi + - type: select + label: Name + schema: schema/properties/spec/properties/target/properties/name + loader: + name: getTargetName + watchPaths: + - schema/properties/spec/properties/target/properties/apiGroup + - schema/properties/spec/properties/target/properties/namespace + - schema/properties/spec/properties/target/properties/kind diff --git a/charts/corekubestashcom-restoresession-editor-options/ui/functions.js b/charts/corekubestashcom-restoresession-editor-options/ui/functions.js index d668e31ed6..13c341430d 100644 --- a/charts/corekubestashcom-restoresession-editor-options/ui/functions.js +++ b/charts/corekubestashcom-restoresession-editor-options/ui/functions.js @@ -1,530 +1,548 @@ -let addonList = [] -function isConsole({ storeGet }) { - const group = storeGet('/route/params/group') || '' - return group !== 'kubedb.com' -} +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} -async function initMetadata({ storeGet, commit, axios }) { - const resource = storeGet('/resource') || {} - const { group, kind } = resource?.layout?.result?.resource - const name = storeGet('/route/params/name') || '' - const namespace = storeGet('route/query/namespace') || '' - if (!isConsole({ storeGet })) { - // set metadata name namespace - commit('wizard/model$update', { - path: '/metadata/release/name', - value: `${name}-${Math.floor(Date.now() / 1000)}-restore`, - force: true, - }) - commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, - force: true, - }) +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) - const target = { - apiGroup: group, - kind: kind, - name: name, - namespace: namespace, - } - commit('wizard/model$update', { - path: '/spec/target', - value: target, - force: true, - }) + /********** Initialize Discriminator **************/ - // set addon name - commit('wizard/model$update', { - path: '/spec/addon/name', - value: `${kind.toLowerCase()}-addon`, - }) + setDiscriminatorValue('database', {}) + setDiscriminatorValue('nameSpaceApi', false) + setDiscriminatorValue('repository', '') + setDiscriminatorValue('params', '') + + let addonList = [] + function isConsole() { + const group = storeGet('/route/params/group') || '' + return group !== 'kubedb.com' } - // get encryptionSecret from stash-preset - await getPreset({ axios, storeGet, commit }) -} + async function initMetadata() { + const resource = storeGet('/resource') || {} + const { group, kind } = resource?.layout?.result?.resource + const name = storeGet('/route/params/name') || '' + const namespace = storeGet('route/query/namespace') || '' + if (!isConsole()) { + // set metadata name namespace + commit('wizard/model$update', { + path: '/metadata/release/name', + value: `${name}-${Math.floor(Date.now() / 1000)}-restore`, + force: true, + }) + commit('wizard/model$update', { + path: '/metadata/release/namespace', + value: namespace, + force: true, + }) -async function getPreset({ axios, storeGet, commit }) { - const user = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${user}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/stash-presets` - try { - const resp = await axios.get(url) - const encryptionSecret = resp?.data?.spec?.values?.spec?.backup?.kubestash?.encryptionSecret - commit('wizard/model$update', { - path: '/spec/dataSource/encryptionSecret', - value: encryptionSecret, - force: true, - }) - } catch (e) { - console.log(e) + const target = { + apiGroup: group, + kind: kind, + name: name, + namespace: namespace, + } + commit('wizard/model$update', { + path: '/spec/target', + value: target, + force: true, + }) + + // set addon name + commit('wizard/model$update', { + path: '/spec/addon/name', + value: `${kind.toLowerCase()}-addon`, + }) + } + + // get encryptionSecret from stash-preset + await getPreset() + setSecurityContext() } -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + async function getPreset() { + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${user}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/stash-presets` + try { + const resp = await axios.get(url) + const encryptionSecret = resp?.data?.spec?.values?.spec?.backup?.kubestash?.encryptionSecret + commit('wizard/model$update', { + path: '/spec/dataSource/encryptionSecret', + value: encryptionSecret, + force: true, + }) + } catch (e) { + console.log(e) + } + } -async function fetchNamespacesApi({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + async function fetchNamespacesApi() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function setNamespace({ storeGet, model, getValue }) { - const namespaceFromModel = getValue(model, '/metadata/release/namespace') - const namespace = storeGet('/route/query/namespace') || namespaceFromModel || '' - return namespace -} + function setNamespace() { + const namespaceFromModel = getValue(model, '/metadata/release/namespace') + const namespace = storeGet('/route/query/namespace') || namespaceFromModel || '' + return namespace + } -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core.k8s.appscode.com/v1alpha1/namespaces/${namespace}/genericresources`, - { - params: { - convertToTable: true, - labelSelector: 'k8s.io/group=kubedb.com', - }, - }, - ) + async function getDbs() { + // watchDependency('model#/metadata/release/namespace') + const namespace = getValue(model, '/metadata/release/namespace') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resources = (resp && resp.data && resp.data.rows) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core.k8s.appscode.com/v1alpha1/namespaces/${namespace}/genericresources`, + { + params: { + convertToTable: true, + labelSelector: 'k8s.io/group=kubedb.com', + }, + }, + ) - return resources.map((item) => { - const name = (item.cells?.length > 0 && item.cells[0].data) || '' - const kind = (item.cells?.length > 2 && item.cells[2].data) || '' - const dbObject = { - apiGroup: 'kubedb.com', - kind: kind, - name: name, - namespace: namespace, - } - return { - text: name, - value: dbObject, - } - }) -} + const resources = (resp && resp.data && resp.data.rows) || [] -function initTarget({ getValue, discriminator, commit }) { - const target = getValue(discriminator, '/database') || {} - commit('wizard/model$update', { - path: '/metadata/release/name', - value: `${target.name}-${Math.floor(Date.now() / 1000)}-restore` || '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/target', - value: target, - force: true, - }) -} - -async function getRepositories({ getValue, model, storeGet, axios }) { - const user = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = storeGet('/route/query/namespace') || '' - const activeOrg = storeGet('/activeOrganization') || '' - const orgList = storeGet('/organizations') || [] - const activeOrgObj = orgList.find((item) => item.username === activeOrg) - const orgType = activeOrgObj?.orgType - - let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/repositories` - if (orgType === 3) { - url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` + return resources.map((item) => { + const name = (item.cells?.length > 0 && item.cells[0].data) || '' + const kind = (item.cells?.length > 2 && item.cells[2].data) || '' + const dbObject = { + apiGroup: 'kubedb.com', + kind: kind, + name: name, + namespace: namespace, + } + return { + text: name, + value: dbObject, + } + }) } - try { - const resp = await axios.get(url) - let names = resp?.data?.items - names.map((item) => { - item.value = { name: item?.metadata?.name, namespace: item?.metadata?.namespace } || {} - item.text = `${item?.metadata?.namespace}/${item?.metadata?.name}` || '' - return true + function initTarget() { + const target = getValue(discriminator, '/database') || {} + commit('wizard/model$update', { + path: '/metadata/release/name', + value: `${target.name}-${Math.floor(Date.now() / 1000)}-restore` || '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/target', + value: target, + force: true, }) - - const resource = storeGet('/resource/layout/result/resource') || {} - let group = resource?.group || '' - let kind = resource?.kind || '' - - if (isConsole({ storeGet })) { - group = getValue(model, '/spec/target/apiGroup') || '' - kind = getValue(model, '/spec/target/kind') || '' - } - if (kind && group) { - const filteredRepo = names.filter((item) => { - const appRef = item?.spec?.appRef || {} - return appRef?.apiGroup === group && appRef?.kind === kind - }) - return filteredRepo - } else { - return names - } - } catch (e) { - console.log(e) } - return [] -} - -function onRepoChange({ getValue, discriminator, commit }) { - const repo = getValue(discriminator, '/repository') - commit('wizard/model$update', { - path: '/spec/dataSource/repository', - value: repo, - force: true, - }) -} -async function getSnapshots({ watchDependency, discriminator, storeGet, getValue, axios }) { - watchDependency('discriminator#/repository') - const user = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const core = 'storage.kubestash.com' - const version = 'v1alpha1' - const repo = getValue(discriminator, '/repository') || {} - const namespace = repo.namespace || '' - const repository = repo.name || '' - - const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/snapshots` + async function getRepositories() { + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = storeGet('/route/query/namespace') || '' + const activeOrg = storeGet('/activeOrganization') || '' + const orgList = storeGet('/organizations') || [] + const activeOrgObj = orgList.find((item) => item.username === activeOrg) + const orgType = activeOrgObj?.orgType + + let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/repositories` + if (orgType === 3) { + url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` + } - try { - if (namespace) { + try { const resp = await axios.get(url) - let snapshots = resp?.data?.items - snapshots.map((item) => { - const name = item?.metadata?.name - item.value = name - item.text = name + let names = resp?.data?.items + names.map((item) => { + item.value = { name: item?.metadata?.name, namespace: item?.metadata?.namespace } || {} + item.text = `${item?.metadata?.namespace}/${item?.metadata?.name}` || '' return true }) - const filteredSnapshots = - snapshots.filter((item) => { - const owners = item?.metadata?.ownerReferences || [] - if (owners.length) return owners[0].name === repository && owners[0].kind === 'Repository' - }) || [] - - filteredSnapshots.forEach((item) => { - const time = item.status?.snapshotTime || '' - // get the time difference and add it to subtext - item.subText = getTimeDiffs(time) - }) - if (filteredSnapshots.length) - filteredSnapshots[0].subText = '(Latest) ' + filteredSnapshots[0].subText - return filteredSnapshots + const resource = storeGet('/resource/layout/result/resource') || {} + let group = resource?.group || '' + let kind = resource?.kind || '' + + if (isConsole()) { + group = getValue(model, '/spec/target/apiGroup') || '' + kind = getValue(model, '/spec/target/kind') || '' + } + if (kind && group) { + const filteredRepo = names.filter((item) => { + const appRef = item?.spec?.appRef || {} + return appRef?.apiGroup === group && appRef?.kind === kind + }) + return filteredRepo + } else { + return names + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} - -function getTimeDiffs(time) { - if (time === '') return '' - const now = new Date() - const timeConvert = new Date(time) - diffInMs = now - timeConvert + function onRepoChange() { + const repo = getValue(discriminator, '/repository') + commit('wizard/model$update', { + path: '/spec/dataSource/repository', + value: repo, + force: true, + }) + } - // const diffInSeconds = Math.floor(diffInMs / 1000) % 60 - const diffInMinutes = Math.floor(diffInMs / (1000 * 60)) % 60 - const diffInHours = Math.floor(diffInMs / (1000 * 60 * 60)) % 24 - const diffInDays = Math.floor(diffInMs / (1000 * 60 * 60 * 24)) + async function getSnapshots() { + // watchDependency('discriminator#/repository') + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const core = 'storage.kubestash.com' + const version = 'v1alpha1' + const repo = getValue(discriminator, '/repository') || {} + const namespace = repo.namespace || '' + const repository = repo.name || '' - let timeDiff = '' - if (diffInDays) timeDiff += `${diffInDays} ${diffInDays > 1 ? 'days' : 'day'} ` - if (diffInHours) timeDiff += `${diffInHours} ${diffInHours > 1 ? 'hours' : 'hour'} ` - if (diffInMinutes) timeDiff += `${diffInMinutes} ${diffInMinutes > 1 ? 'minutes' : 'minute'}` - if (!diffInMinutes) return 'Just now' - return ` ${timeDiff} ago` -} + const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/snapshots` -async function getAddons({ storeGet, axios, commit }) { - const user = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons` - if (isConsole({ storeGet })) { try { - const resp = await axios.get(url) - let addons = resp?.data?.items - addonList = addons - - addons = addons.map((item) => item?.metadata?.name) - - const kind = storeGet('/resource/layout/result/resource/kind') - if (kind) { - const found = addons.find((item) => item.startsWith(kind.toLowerCase())) - commit('wizard/model$update', { - path: '/spec/addon/name', - value: found, - force: true, + if (namespace) { + const resp = await axios.get(url) + let snapshots = resp?.data?.items + snapshots.map((item) => { + const name = item?.metadata?.name + item.value = name + item.text = name + return true + }) + const filteredSnapshots = + snapshots.filter((item) => { + const owners = item?.metadata?.ownerReferences || [] + if (owners.length) + return owners[0].name === repository && owners[0].kind === 'Repository' + }) || [] + + filteredSnapshots.forEach((item) => { + const time = item.status?.snapshotTime || '' + // get the time difference and add it to subtext + item.subText = getTimeDiffs(time) }) + if (filteredSnapshots.length) + filteredSnapshots[0].subText = '(Latest) ' + filteredSnapshots[0].subText + + return filteredSnapshots } - return addons } catch (e) { console.log(e) } + return [] } - return [] -} -function getTasks({ watchDependency, model, getValue }) { - watchDependency('model#/spec/addon/name') - const addon = getValue(model, '/spec/addon/name') - const addonDetails = addonList?.find((item) => item?.metadata?.name === addon) - let tasks = addonDetails?.spec?.restoreTasks - tasks = tasks?.map((item) => item?.name) - return tasks -} + function getTimeDiffs(time) { + if (time === '') return '' -function databaseSelected({ storeGet, watchDependency, getValue, discriminator }) { - isKube = storeGet('/route/params/actions') - if (isKube) return true - watchDependency('discriminator#/database') - const target = getValue(discriminator, '/database') || {} - return !!target.name -} + const now = new Date() + const timeConvert = new Date(time) + const diffInMs = now - timeConvert -const securityContextMap = { - MongoDB: 999, - Postgres: 70, - Elasticsearch: 1000, - MSSQLServer: 10001, - MySQL: 999, - MariaDB: 999, - Redis: 999, - Singlestore: 999, - ZooKeeper: 999, -} + // const diffInSeconds = Math.floor(diffInMs / 1000) % 60 + const diffInMinutes = Math.floor(diffInMs / (1000 * 60)) % 60 + const diffInHours = Math.floor(diffInMs / (1000 * 60 * 60)) % 24 + const diffInDays = Math.floor(diffInMs / (1000 * 60 * 60 * 24)) -async function setSecurityContext({ storeGet, commit, axios }) { - const namespace = storeGet('/route/query/namespace') || '' - const user = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - if (namespace) { - const url = `clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}` - try { - const resp = await axios.get(url) - const annotations = resp.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] - commit('wizard/model$update', { - path: '/spec/addon/jobTemplate/securityContext', - value: val, - force: true, - }) - } else { - const kind = storeGet('/resource/layout/result/resource/kind') || '' - const context = securityContextMap[kind] + let timeDiff = '' + if (diffInDays) timeDiff += `${diffInDays} ${diffInDays > 1 ? 'days' : 'day'} ` + if (diffInHours) timeDiff += `${diffInHours} ${diffInHours > 1 ? 'hours' : 'hour'} ` + if (diffInMinutes) timeDiff += `${diffInMinutes} ${diffInMinutes > 1 ? 'minutes' : 'minute'}` + if (!diffInMinutes) return 'Just now' + return ` ${timeDiff} ago` + } - commit('wizard/model$update', { - path: '/spec/addon/jobTemplate/securityContext', - value: context, - force: true, - }) + async function getAddons() { + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons` + if (isConsole()) { + try { + const resp = await axios.get(url) + let addons = resp?.data?.items + addonList = addons + + addons = addons.map((item) => item?.metadata?.name) + + const kind = storeGet('/resource/layout/result/resource/kind') + if (kind) { + const found = addons.find((item) => item.startsWith(kind.toLowerCase())) + commit('wizard/model$update', { + path: '/spec/addon/name', + value: found, + force: true, + }) + } + return addons + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) } + return [] } -} -function returnFalse() { - return false -} + function getTasks() { + // watchDependency('model#/spec/addon/name') + const addon = getValue(model, '/spec/addon/name') + const addonDetails = addonList?.find((item) => item?.metadata?.name === addon) + let tasks = addonDetails?.spec?.restoreTasks + tasks = tasks?.map((item) => item?.name) + return tasks + } -let appKind = [] -let coreKind = [] -let kubedbKind = [] -let availableKinds = {} -let kindToResourceMap = {} -let namespaces = [] -let version = '' - -function init({ watchDependency, model, getValue, storeGet, axios }) { - getKindsApi({ watchDependency, model, getValue, storeGet, axios }) - namespaces = fetchNamespacesApi({ axios, storeGet }) -} + function databaseSelected() { + isKube = storeGet('/route/params/actions') + if (isKube) return true + // watchDependency('discriminator#/database') + const target = getValue(discriminator, '/database') || {} + return !!target.name + } -function fetchNamespaces({ watchDependency }) { - watchDependency('discriminator#/nameSpaceApi') - return namespaces -} + const securityContextMap = { + MongoDB: 999, + Postgres: 70, + Elasticsearch: 1000, + MSSQLServer: 10001, + MySQL: 999, + MariaDB: 999, + Redis: 999, + Singlestore: 999, + ZooKeeper: 999, + } -function setVersion({ getValue, model, watchDependency }) { - watchDependency('model#/spec/target/apiGroup') - watchDependency('model#/spec/target/kind') - const apiGroup = getValue(model, `/spec/target/apiGroup`) - const kind = getValue(model, `/spec/target/kind`) - if (apiGroup === 'core') apiGroup = '' - Object.keys(availableKinds[apiGroup]).forEach((vs) => { - availableKinds[apiGroup][vs].forEach((ele) => { - if (ele.Kind === kind) { - version = vs + async function setSecurityContext() { + const namespace = storeGet('/route/query/namespace') || '' + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + if (namespace) { + const url = `clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { + const resp = await axios.get(url) + const annotations = resp.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/addon/jobTemplate/securityContext', + value: val, + force: true, + }) + } else { + const kind = storeGet('/resource/layout/result/resource/kind') || '' + const context = securityContextMap[kind] + + commit('wizard/model$update', { + path: '/spec/addon/jobTemplate/securityContext', + value: context, + force: true, + }) + } + } catch (e) { + console.log(e) } - }) - }) -} + } + } -async function getKindsApi({ storeGet, axios }) { - const params = storeGet('/route/params') - const { user, cluster } = params - let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` - try { - const resp = await axios.get(url) + function returnFalse() { + return false + } - kindToResourceMap['kubedb.com'] = {} - kindToResourceMap['apps'] = {} - kindToResourceMap['core'] = {} + let appKind = [] + let coreKind = [] + let kubedbKind = [] + let availableKinds = {} + let kindToResourceMap = {} + let namespaces = [] + let version = '' + + function init() { + getKindsApi() + namespaces = fetchNamespacesApi() + } - availableKinds = resp.data + function fetchNamespaces() { + // watchDependency('discriminator#/nameSpaceApi') + return namespaces + } - appKind = Object.values(availableKinds['apps']) - .flat() - .map((ele) => { - kindToResourceMap['apps'][ele.Kind] = ele.Resource - return ele.Kind - }) - kubedbKind = Object.values(availableKinds['kubedb.com']) - .flat() - .map((ele) => { - kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource - return ele.Kind + function setVersion() { + // watchDependency('model#/spec/target/apiGroup') + // watchDependency('model#/spec/target/kind') + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const kind = getValue(model, `/spec/target/kind`) + if (apiGroup === 'core') apiGroup = '' + Object.keys(availableKinds[apiGroup]).forEach((vs) => { + availableKinds[apiGroup][vs].forEach((ele) => { + if (ele.Kind === kind) { + version = vs + } }) - coreKind = Object.values(availableKinds['']) - .flat() - .map((ele) => { - kindToResourceMap['core'][ele.Kind] = ele.Resource - return ele.Kind - }) - } catch (e) { - console.log(e) + }) } - return [] -} -function getKinds({ watchDependency, getValue, model }) { - watchDependency(`model#/spec/target/apiGroup`) - const apiGroup = getValue(model, `/spec/target/apiGroup`) + async function getKindsApi() { + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` + try { + const resp = await axios.get(url) - if (apiGroup === 'core') return coreKind - else if (apiGroup === 'apps') return appKind - else return kubedbKind -} + kindToResourceMap['kubedb.com'] = {} + kindToResourceMap['apps'] = {} + kindToResourceMap['core'] = {} -function getApiGroup() { - return ['core', 'apps', 'kubedb.com'] -} + availableKinds = resp.data -async function getTargetName({ watchDependency, getValue, model, axios, storeGet }) { - watchDependency('model#/spec/target/apiGroup') - watchDependency('model#/spec/target/namespace') - watchDependency('model#/spec/target/kind') - const apiGroup = getValue(model, `/spec/target/apiGroup`) - const namespace = getValue(model, `/spec/target/namespace`) - const resource = getResourceName({ getValue, model }) - const params = storeGet('/route/params') - const { user, cluster } = params - - const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` - if (apiGroup && version && resource && namespace) { - try { - const resp = await axios.get(url) - const items = resp.data?.items - const options = items.map((ele) => { - return ele.metadata.name - }) - return options + appKind = Object.values(availableKinds['apps']) + .flat() + .map((ele) => { + kindToResourceMap['apps'][ele.Kind] = ele.Resource + return ele.Kind + }) + kubedbKind = Object.values(availableKinds['kubedb.com']) + .flat() + .map((ele) => { + kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource + return ele.Kind + }) + coreKind = Object.values(availableKinds['']) + .flat() + .map((ele) => { + kindToResourceMap['core'][ele.Kind] = ele.Resource + return ele.Kind + }) } catch (e) { console.log(e) } + return [] } -} -function getResourceName({ getValue, model }) { - const apiGroup = getValue(model, `/spec/target/apiGroup`) - const kind = getValue(model, `/spec/target/kind`) - if (!kind || !apiGroup) return '' - return kindToResourceMap[apiGroup][kind] -} + function getKinds() { + // watchDependency(`model#/spec/target/apiGroup`) + const apiGroup = getValue(model, `/spec/target/apiGroup`) -function onParameterChange({ getValue, model, discriminator, commit }) { - const tasks = getValue(model, '/spec/addon/tasks') || [] - const params = getValue(discriminator, '/params') - tasks[0]['params'] = params - commit('wizard/model$update', { - path: '/spec/addon/tasks', - value: tasks, - force: true, - }) -} + if (apiGroup === 'core') return coreKind + else if (apiGroup === 'apps') return appKind + else return kubedbKind + } + + function getApiGroup() { + return ['core', 'apps', 'kubedb.com'] + } + + async function getTargetName() { + // watchDependency('model#/spec/target/apiGroup') + // watchDependency('model#/spec/target/namespace') + // watchDependency('model#/spec/target/kind') + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const namespace = getValue(model, `/spec/target/namespace`) + const resource = getResourceName() + const params = storeGet('/route/params') + const { user, cluster } = params + + const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` + if (apiGroup && version && resource && namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + const options = items.map((ele) => { + return ele.metadata.name + }) + return options + } catch (e) { + console.log(e) + } + } + } + + function getResourceName() { + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const kind = getValue(model, `/spec/target/kind`) + if (!kind || !apiGroup) return '' + return kindToResourceMap[apiGroup][kind] + } + + function onParameterChange() { + const tasks = getValue(model, '/spec/addon/tasks') || [] + const params = getValue(discriminator, '/params') + tasks[0]['params'] = params + commit('wizard/model$update', { + path: '/spec/addon/tasks', + value: tasks, + force: true, + }) + } -return { - isRancherManaged, - fetchNamespaces, - setVersion, - init, - getTargetName, - getKinds, - getApiGroup, - isConsole, - initMetadata, - getPreset, - fetchNamespacesApi, - setNamespace, - getDbs, - initTarget, - getRepositories, - onRepoChange, - getSnapshots, - getAddons, - getTasks, - databaseSelected, - returnFalse, - onParameterChange, - setSecurityContext, + return { + isRancherManaged, + fetchNamespaces, + setVersion, + init, + getTargetName, + getKinds, + getApiGroup, + isConsole, + initMetadata, + getPreset, + fetchNamespacesApi, + setNamespace, + getDbs, + initTarget, + getRepositories, + onRepoChange, + getSnapshots, + getAddons, + getTasks, + databaseSelected, + returnFalse, + onParameterChange, + setSecurityContext, + } } diff --git a/charts/corekubestashcom-restoresession-editor-options/ui/old.create-ui.yaml b/charts/corekubestashcom-restoresession-editor-options/ui/old.create-ui.yaml new file mode 100644 index 0000000000..8daa59492d --- /dev/null +++ b/charts/corekubestashcom-restoresession-editor-options/ui/old.create-ui.yaml @@ -0,0 +1,125 @@ +steps: +- form: + elements: + - discriminator: + database: + default: {} + type: object + nameSpaceApi: + default: false + type: boolean + elements: + - fetch: fetchNamespaces + hasGroup: isRancherManaged + if: isConsole + label: + text: Select Namespace + schema: + $ref: schema#/properties/metadata/properties/release/properties/namespace + type: select + - computed: init + if: returnFalse + type: input + - if: isConsole + label: + text: labels.name + schema: + $ref: schema#/properties/metadata/properties/release/properties/name + type: input + - elements: + - computed: initMetadata + if: returnFalse + type: input + - discriminator: + repository: + type: object + elements: + - disableUnselect: true + fetch: getRepositories + label: + text: Repository + onChange: onRepoChange + refresh: true + required: true + schema: + $ref: discriminator#/properties/repository + type: select + - disableUnselect: true + fetch: getSnapshots + label: + text: labels.dataSource.snapshot + refresh: true + schema: + $ref: schema#/properties/spec/properties/dataSource/properties/snapshot + type: select + schema: + $ref: schema#/properties/spec/properties/dataSource + type: single-step-form + - discriminator: + params: + default: "" + type: string + elements: + - fetch: getAddons + if: isConsole + label: + text: labels.name + refresh: true + schema: + $ref: schema#/properties/spec/properties/addon/properties/name + type: select + - label: + text: Additional Parameters + onChange: onParameterChange + schema: + $ref: discriminator#/properties/params + type: textarea + - computed: setSecurityContext + if: returnFalse + type: input + schema: + $ref: schema#/properties/spec/properties/addon + type: single-step-form + - elements: + - fetch: getApiGroup + label: + text: Api Group + schema: + $ref: schema#/properties/spec/properties/target/properties/apiGroup + type: select + - fetch: getKinds + label: + text: Kind + onChange: setVersion + schema: + $ref: schema#/properties/spec/properties/target/properties/kind + type: select + - fetch: fetchNamespaces + hasGroup: isRancherManaged + label: + text: Namespace + schema: + $ref: schema#/properties/spec/properties/target/properties/namespace + type: select + - fetch: getTargetName + label: + text: Name + schema: + $ref: schema#/properties/spec/properties/target/properties/name + type: select + hideForm: true + if: isConsole + label: + text: Target + schema: + $ref: schema#/properties/spec/properties/target + show_label: true + type: single-step-form + schema: + $ref: schema#/properties/spec + type: single-step-form + type: single-step-form + type: single-step-form + id: options + title: steps.0.label +type: multi-step-form diff --git a/charts/corekubestashcom-restoresession-editor-options/ui/old.functions.js b/charts/corekubestashcom-restoresession-editor-options/ui/old.functions.js new file mode 100644 index 0000000000..d668e31ed6 --- /dev/null +++ b/charts/corekubestashcom-restoresession-editor-options/ui/old.functions.js @@ -0,0 +1,530 @@ +let addonList = [] +function isConsole({ storeGet }) { + const group = storeGet('/route/params/group') || '' + return group !== 'kubedb.com' +} + +async function initMetadata({ storeGet, commit, axios }) { + const resource = storeGet('/resource') || {} + const { group, kind } = resource?.layout?.result?.resource + const name = storeGet('/route/params/name') || '' + const namespace = storeGet('route/query/namespace') || '' + if (!isConsole({ storeGet })) { + // set metadata name namespace + commit('wizard/model$update', { + path: '/metadata/release/name', + value: `${name}-${Math.floor(Date.now() / 1000)}-restore`, + force: true, + }) + commit('wizard/model$update', { + path: '/metadata/release/namespace', + value: namespace, + force: true, + }) + + const target = { + apiGroup: group, + kind: kind, + name: name, + namespace: namespace, + } + commit('wizard/model$update', { + path: '/spec/target', + value: target, + force: true, + }) + + // set addon name + commit('wizard/model$update', { + path: '/spec/addon/name', + value: `${kind.toLowerCase()}-addon`, + }) + } + + // get encryptionSecret from stash-preset + await getPreset({ axios, storeGet, commit }) +} + +async function getPreset({ axios, storeGet, commit }) { + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${user}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/stash-presets` + try { + const resp = await axios.get(url) + const encryptionSecret = resp?.data?.spec?.values?.spec?.backup?.kubestash?.encryptionSecret + commit('wizard/model$update', { + path: '/spec/dataSource/encryptionSecret', + value: encryptionSecret, + force: true, + }) + } catch (e) { + console.log(e) + } +} + +function isRancherManaged({ storeGet }) { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found +} + +async function fetchNamespacesApi({ axios, storeGet }) { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] +} + +function setNamespace({ storeGet, model, getValue }) { + const namespaceFromModel = getValue(model, '/metadata/release/namespace') + const namespace = storeGet('/route/query/namespace') || namespaceFromModel || '' + return namespace +} + +async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { + watchDependency('model#/metadata/release/namespace') + const namespace = getValue(model, '/metadata/release/namespace') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core.k8s.appscode.com/v1alpha1/namespaces/${namespace}/genericresources`, + { + params: { + convertToTable: true, + labelSelector: 'k8s.io/group=kubedb.com', + }, + }, + ) + + const resources = (resp && resp.data && resp.data.rows) || [] + + return resources.map((item) => { + const name = (item.cells?.length > 0 && item.cells[0].data) || '' + const kind = (item.cells?.length > 2 && item.cells[2].data) || '' + const dbObject = { + apiGroup: 'kubedb.com', + kind: kind, + name: name, + namespace: namespace, + } + return { + text: name, + value: dbObject, + } + }) +} + +function initTarget({ getValue, discriminator, commit }) { + const target = getValue(discriminator, '/database') || {} + commit('wizard/model$update', { + path: '/metadata/release/name', + value: `${target.name}-${Math.floor(Date.now() / 1000)}-restore` || '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/target', + value: target, + force: true, + }) +} + +async function getRepositories({ getValue, model, storeGet, axios }) { + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = storeGet('/route/query/namespace') || '' + const activeOrg = storeGet('/activeOrganization') || '' + const orgList = storeGet('/organizations') || [] + const activeOrgObj = orgList.find((item) => item.username === activeOrg) + const orgType = activeOrgObj?.orgType + + let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/repositories` + if (orgType === 3) { + url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` + } + + try { + const resp = await axios.get(url) + let names = resp?.data?.items + names.map((item) => { + item.value = { name: item?.metadata?.name, namespace: item?.metadata?.namespace } || {} + item.text = `${item?.metadata?.namespace}/${item?.metadata?.name}` || '' + return true + }) + + const resource = storeGet('/resource/layout/result/resource') || {} + let group = resource?.group || '' + let kind = resource?.kind || '' + + if (isConsole({ storeGet })) { + group = getValue(model, '/spec/target/apiGroup') || '' + kind = getValue(model, '/spec/target/kind') || '' + } + if (kind && group) { + const filteredRepo = names.filter((item) => { + const appRef = item?.spec?.appRef || {} + return appRef?.apiGroup === group && appRef?.kind === kind + }) + return filteredRepo + } else { + return names + } + } catch (e) { + console.log(e) + } + return [] +} + +function onRepoChange({ getValue, discriminator, commit }) { + const repo = getValue(discriminator, '/repository') + commit('wizard/model$update', { + path: '/spec/dataSource/repository', + value: repo, + force: true, + }) +} + +async function getSnapshots({ watchDependency, discriminator, storeGet, getValue, axios }) { + watchDependency('discriminator#/repository') + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const core = 'storage.kubestash.com' + const version = 'v1alpha1' + const repo = getValue(discriminator, '/repository') || {} + const namespace = repo.namespace || '' + const repository = repo.name || '' + + const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/snapshots` + + try { + if (namespace) { + const resp = await axios.get(url) + let snapshots = resp?.data?.items + snapshots.map((item) => { + const name = item?.metadata?.name + item.value = name + item.text = name + return true + }) + const filteredSnapshots = + snapshots.filter((item) => { + const owners = item?.metadata?.ownerReferences || [] + if (owners.length) return owners[0].name === repository && owners[0].kind === 'Repository' + }) || [] + + filteredSnapshots.forEach((item) => { + const time = item.status?.snapshotTime || '' + // get the time difference and add it to subtext + item.subText = getTimeDiffs(time) + }) + if (filteredSnapshots.length) + filteredSnapshots[0].subText = '(Latest) ' + filteredSnapshots[0].subText + + return filteredSnapshots + } + } catch (e) { + console.log(e) + } + return [] +} + +function getTimeDiffs(time) { + if (time === '') return '' + + const now = new Date() + const timeConvert = new Date(time) + diffInMs = now - timeConvert + + // const diffInSeconds = Math.floor(diffInMs / 1000) % 60 + const diffInMinutes = Math.floor(diffInMs / (1000 * 60)) % 60 + const diffInHours = Math.floor(diffInMs / (1000 * 60 * 60)) % 24 + const diffInDays = Math.floor(diffInMs / (1000 * 60 * 60 * 24)) + + let timeDiff = '' + if (diffInDays) timeDiff += `${diffInDays} ${diffInDays > 1 ? 'days' : 'day'} ` + if (diffInHours) timeDiff += `${diffInHours} ${diffInHours > 1 ? 'hours' : 'hour'} ` + if (diffInMinutes) timeDiff += `${diffInMinutes} ${diffInMinutes > 1 ? 'minutes' : 'minute'}` + if (!diffInMinutes) return 'Just now' + return ` ${timeDiff} ago` +} + +async function getAddons({ storeGet, axios, commit }) { + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${user}/${cluster}/proxy/addons.kubestash.com/v1alpha1/addons` + if (isConsole({ storeGet })) { + try { + const resp = await axios.get(url) + let addons = resp?.data?.items + addonList = addons + + addons = addons.map((item) => item?.metadata?.name) + + const kind = storeGet('/resource/layout/result/resource/kind') + if (kind) { + const found = addons.find((item) => item.startsWith(kind.toLowerCase())) + commit('wizard/model$update', { + path: '/spec/addon/name', + value: found, + force: true, + }) + } + return addons + } catch (e) { + console.log(e) + } + } + return [] +} + +function getTasks({ watchDependency, model, getValue }) { + watchDependency('model#/spec/addon/name') + const addon = getValue(model, '/spec/addon/name') + const addonDetails = addonList?.find((item) => item?.metadata?.name === addon) + let tasks = addonDetails?.spec?.restoreTasks + tasks = tasks?.map((item) => item?.name) + return tasks +} + +function databaseSelected({ storeGet, watchDependency, getValue, discriminator }) { + isKube = storeGet('/route/params/actions') + if (isKube) return true + watchDependency('discriminator#/database') + const target = getValue(discriminator, '/database') || {} + return !!target.name +} + +const securityContextMap = { + MongoDB: 999, + Postgres: 70, + Elasticsearch: 1000, + MSSQLServer: 10001, + MySQL: 999, + MariaDB: 999, + Redis: 999, + Singlestore: 999, + ZooKeeper: 999, +} + +async function setSecurityContext({ storeGet, commit, axios }) { + const namespace = storeGet('/route/query/namespace') || '' + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + if (namespace) { + const url = `clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { + const resp = await axios.get(url) + const annotations = resp.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/addon/jobTemplate/securityContext', + value: val, + force: true, + }) + } else { + const kind = storeGet('/resource/layout/result/resource/kind') || '' + const context = securityContextMap[kind] + + commit('wizard/model$update', { + path: '/spec/addon/jobTemplate/securityContext', + value: context, + force: true, + }) + } + } catch (e) { + console.log(e) + } + } +} + +function returnFalse() { + return false +} + +let appKind = [] +let coreKind = [] +let kubedbKind = [] +let availableKinds = {} +let kindToResourceMap = {} +let namespaces = [] +let version = '' + +function init({ watchDependency, model, getValue, storeGet, axios }) { + getKindsApi({ watchDependency, model, getValue, storeGet, axios }) + namespaces = fetchNamespacesApi({ axios, storeGet }) +} + +function fetchNamespaces({ watchDependency }) { + watchDependency('discriminator#/nameSpaceApi') + return namespaces +} + +function setVersion({ getValue, model, watchDependency }) { + watchDependency('model#/spec/target/apiGroup') + watchDependency('model#/spec/target/kind') + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const kind = getValue(model, `/spec/target/kind`) + if (apiGroup === 'core') apiGroup = '' + Object.keys(availableKinds[apiGroup]).forEach((vs) => { + availableKinds[apiGroup][vs].forEach((ele) => { + if (ele.Kind === kind) { + version = vs + } + }) + }) +} + +async function getKindsApi({ storeGet, axios }) { + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` + try { + const resp = await axios.get(url) + + kindToResourceMap['kubedb.com'] = {} + kindToResourceMap['apps'] = {} + kindToResourceMap['core'] = {} + + availableKinds = resp.data + + appKind = Object.values(availableKinds['apps']) + .flat() + .map((ele) => { + kindToResourceMap['apps'][ele.Kind] = ele.Resource + return ele.Kind + }) + kubedbKind = Object.values(availableKinds['kubedb.com']) + .flat() + .map((ele) => { + kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource + return ele.Kind + }) + coreKind = Object.values(availableKinds['']) + .flat() + .map((ele) => { + kindToResourceMap['core'][ele.Kind] = ele.Resource + return ele.Kind + }) + } catch (e) { + console.log(e) + } + return [] +} + +function getKinds({ watchDependency, getValue, model }) { + watchDependency(`model#/spec/target/apiGroup`) + const apiGroup = getValue(model, `/spec/target/apiGroup`) + + if (apiGroup === 'core') return coreKind + else if (apiGroup === 'apps') return appKind + else return kubedbKind +} + +function getApiGroup() { + return ['core', 'apps', 'kubedb.com'] +} + +async function getTargetName({ watchDependency, getValue, model, axios, storeGet }) { + watchDependency('model#/spec/target/apiGroup') + watchDependency('model#/spec/target/namespace') + watchDependency('model#/spec/target/kind') + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const namespace = getValue(model, `/spec/target/namespace`) + const resource = getResourceName({ getValue, model }) + const params = storeGet('/route/params') + const { user, cluster } = params + + const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` + if (apiGroup && version && resource && namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + const options = items.map((ele) => { + return ele.metadata.name + }) + return options + } catch (e) { + console.log(e) + } + } +} + +function getResourceName({ getValue, model }) { + const apiGroup = getValue(model, `/spec/target/apiGroup`) + const kind = getValue(model, `/spec/target/kind`) + if (!kind || !apiGroup) return '' + return kindToResourceMap[apiGroup][kind] +} + +function onParameterChange({ getValue, model, discriminator, commit }) { + const tasks = getValue(model, '/spec/addon/tasks') || [] + const params = getValue(discriminator, '/params') + tasks[0]['params'] = params + commit('wizard/model$update', { + path: '/spec/addon/tasks', + value: tasks, + force: true, + }) +} + +return { + isRancherManaged, + fetchNamespaces, + setVersion, + init, + getTargetName, + getKinds, + getApiGroup, + isConsole, + initMetadata, + getPreset, + fetchNamespacesApi, + setNamespace, + getDbs, + initTarget, + getRepositories, + onRepoChange, + getSnapshots, + getAddons, + getTasks, + databaseSelected, + returnFalse, + onParameterChange, + setSecurityContext, +} diff --git a/charts/kubedbcom-cassandra-editor-options/ui/create-ui.yaml b/charts/kubedbcom-cassandra-editor-options/ui/create-ui.yaml index 64f1927be8..96a08818d7 100644 --- a/charts/kubedbcom-cassandra-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-cassandra-editor-options/ui/create-ui.yaml @@ -1,341 +1,318 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Cassandra/versions - if: isToggleOn|databases/Cassandra/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Cassandra/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Cassandra/versions + if: + type: function + name: isToggleOn|databases/Cassandra/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Cassandra/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Cassandra/mode + loader: getAdminOptions|databases/Cassandra/mode + if: + type: function + name: isToggleOn|databases/Cassandra/mode + label: Database mode + isHorizontal: true + watcher: + func: toggleTls + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Replicaset number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/Cassandra/mode - fetch: getAdminOptions|databases/Cassandra/mode - hasDescription: true - if: isToggleOn|databases/Cassandra/mode - label: - text: labels.database.mode - onChange: toggleTls - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: isEqualToModelPathValue|Topology|/spec/mode - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine profile + showLabels: true + type: block-layout + - elements: + - type: array-item-form + element: + label: Rack names + schema: schema/properties/spec/properties/topology/properties/racks/items type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form + validation: + type: custom + name: validateRackName + label: Rack name + schema: schema/properties/spec/properties/topology/properties/racks + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Topology + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - element: - label: - isSubsection: true - text: Rack names - schema: - $ref: schema#/properties/spec/properties/topology/properties/racks/items - type: input - validationRuleObject: - errorText: The value must start with a letter, can include letters, numbers, - hyphens (-), and underscores (_). - regex: ^[A-Za-z][A-Za-z0-9_-]*[A-Za-z0-9]$ - label: - text: Rack name - required: true - schema: - $ref: schema#/properties/spec/properties/topology/properties/racks - type: list-input-form - if: isEqualToModelPathValue|Topology|/spec/mode - label: - text: Topology - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup - type: switch - - elements: - - computed: toggleTls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - if: isEqualToModelPathValue|Topology|/spec/mode - type: single-step-form - - if: isToggleOn|expose - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - init: + type: func + value: toggleTls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default + type: select + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + type: block-layout + - if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default + type: switch + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-cassandra-editor-options/ui/functions.js b/charts/kubedbcom-cassandra-editor-options/ui/functions.js index e9111a3411..f3c10718dd 100644 --- a/charts/kubedbcom-cassandra-editor-options/ui/functions.js +++ b/charts/kubedbcom-cassandra-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1063 +317,857 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } - const resources = (resp && resp.data && resp.data.items) || [] + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options + } -async function getMySqlVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } - const resources = (resp && resp.data && resp.data.items) || [] + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } - // keep only non deprecated versions - const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] - filteredMySqlVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMySqlVersions -} + if (available.length) { + array = available.map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } + }) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array + } -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } - if (owner && cluster && namespace) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, - }, - }, - }, - }, - ) + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } - const secrets = (resp && resp.data && resp.data.items) || [] + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } + } - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, }) - return filteredSecrets - } catch (e) { - console.log(e) + return memory + } else { + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - return [] -} -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + commit('wizard/model$update', { + path: commitPath, + value: val, + force: true, }) - } else { - array = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } - }) - .filter((val) => !!val) } - return array -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + function validateRackName() { + // watchDependency('model#/spec/topology/racks') + const regex = /^[A-Za-z][A-Za-z0-9_-]*[A-Za-z0-9]$/ + const racks = getValue(model, '/spec/topology/racks') || [] + for (let rack of racks) { + if (!regex.test(rack)) { + return 'The value must start with a letter, can include letters, numbers, hyphens (-), and underscores (_).' + } + } + return true } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setReplicaNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 2 - } else return 1 -} -function setRouterNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 3 - } else return 1 -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } -} - -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + if (val === 'capz' && ifDedicated()) return true + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] - } + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb]`, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } } - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Cassandra/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Cassandra/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Cassandra/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) + + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') + + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + + function returnFalse() { + return false } - setDiscriminatorValue('/bundleApiLoaded', true) -} + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let namespaces = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!getValue(model, `/spec/admin/databases/Cassandra/mode/toggle`)) { + let defMode = getDefault('databases/Cassandra/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Cassandra/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + namespaces = getNamespaces() + setDiscriminatorValue('/bundleApiLoaded', true) } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + function fetchNamespaces() { + // watchDependency('discriminator#/bundleApiLoaded') + return namespaces } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } + + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } + + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } + + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + setDiscriminatorValue('/isBackupToggleOn', true) + console.log('Backup toggle is changed to ON/OFF. Updating backup tool to KubeStash/empty.') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + } + + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} - -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') - - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist } -} - -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} - -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} - -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory - } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue - } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory - } + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val } - if (resource === 'memory') { + function onAuthChange() { commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: '/spec/authSecret/name', + value: '', force: true, }) commit('wizard/model$update', { - path: comparePath, - value: memory, + path: '/spec/authSecret/password', + value: '', force: true, }) - return memory - } else { + } + + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } + + function toggleTls() { + let modelPathValue = getValue(model, '/spec/mode') commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/admin/tls/default', + value: modelPathValue !== 'Standalone', force: true, }) commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/tls/toggle', + value: modelPathValue !== 'Standalone', force: true, }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} -function toggleTls({ commit, model, getValue }) { - let modelPathValue = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: modelPathValue !== 'Standalone', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/admin/tls/toggle', - value: modelPathValue !== 'Standalone', - force: true, - }) -} - -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} - -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} - -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} - -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val } - return options -} - -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} - -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} - -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} - -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + const projects = resp?.data?.status?.projects + if (projects) { + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + namespaces = projectsNamespace + } else { + namespaces = resp?.data?.status?.namespaces || [] + } + return namespaces + } catch (e) { + console.log(e) + return [] + } + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - setLimits, - setRequests, - toggleTls, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - returnFalse, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - showStorageSizeField, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - getResources, - getMySqlVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - setReplicaNumber, - setRouterNumber, - setBackup, - showAdditionalSettings, - getDefault, + return { + onReferSecretChange, + showReferSecretSwitch, + getDefaultValue, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + toggleTls, + isRancherManaged, + fetchNamespaces, + showAdditionalSettings, + returnFalse, + initBundle, + isVariantAvailable, + isEqualToModelPathValue, + getNamespaces, + isMachineNotCustom, + isMachineCustom, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAlertValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + isConfigDatabaseOn, + clearConfiguration, + isToggleOn, + getAdminOptions, + onBackupSwitch, + showAlerts, + showIssuer, + setMonitoring, + getNodeTopology, + filterNodeTopology, + onAuthChange, + setBackup, + getDefault, + validateRackName, + } } diff --git a/charts/kubedbcom-clickhouse-editor-options/ui/create-ui.yaml b/charts/kubedbcom-clickhouse-editor-options/ui/create-ui.yaml index c946b1d696..689b7ac2c3 100644 --- a/charts/kubedbcom-clickhouse-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-clickhouse-editor-options/ui/create-ui.yaml @@ -1,353 +1,326 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/ClickHouse/versions - if: isToggleOn|databases/ClickHouse/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/ClickHouse/properties/versions/properties/default - type: select - - computed: getDefault|databases/ClickHouse/mode - fetch: getAdminOptions|databases/ClickHouse/mode - hasDescription: true - if: isToggleOn|databases/ClickHouse/mode - label: - text: labels.database.mode - onChange: clearArbiterHidden - schema: - $ref: schema#/properties/spec/properties/mode - type: radio +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/ClickHouse/versions + if: + type: function + name: isToggleOn|databases/ClickHouse/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/ClickHouse/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/ClickHouse/mode + loader: getAdminOptions|databases/ClickHouse/mode + if: + type: function + name: isToggleOn|databases/ClickHouse/mode + label: Database mode + isHorizontal: true + watcher: + func: clearArbiterHidden + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - elements: - elements: - - elements: - - label: - text: labels.cluster.replicas - schema: - $ref: schema#/properties/spec/properties/topology/properties/cluster/properties/replicas - type: input - - label: - text: labels.cluster.shards - schema: - $ref: schema#/properties/spec/properties/topology/properties/cluster/properties/shards - type: input - label: - text: labels.cluster.cluster - show_label: true - type: single-step-form - if: isEqualToModelPathValue|Topology|/spec/mode - type: single-step-form + - label: Cluster replicas + schema: schema/properties/spec/properties/topology/properties/cluster/properties/replicas + type: input + - label: Cluster shards + schema: schema/properties/spec/properties/topology/properties/cluster/properties/shards + type: input + label: Cluster + showLabels: true + type: block-layout + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: showStorageSizeField + label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - label: Externally Managed? + schema: schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/externallyManaged + type: switch + - elements: + - customClass: mt-10 + label: Host + schema: schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/node/properties/host + type: input + - label: Port + schema: schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/node/properties/port + type: input + if: + type: function + name: isExternallyManaged|true + label: Node + showLabels: true + type: block-layout + - elements: + - customClass: mt-10 + label: Size + schema: schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/persistence/properties/size + type: input + - label: Replicas + schema: schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/replicas + type: input - elements: - - computed: setMachineToCustom + - init: + type: func + value: setMachineToCustom customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/podResources/properties/machine type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + - init: + type: func + value: setLimits|cpu|topology/clickHouseKeeper/spec + if: + type: function + name: isMachineCustom|topology/clickHouseKeeper/spec + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + - init: + type: func + value: setLimits|memory|topology/clickHouseKeeper/spec + if: + type: function + name: isMachineCustom|topology/clickHouseKeeper/spec + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.select - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + label: Machine profile + showLabels: true + type: block-layout + if: + type: function + name: isExternallyManaged|false + label: Spec + showLabels: true + type: block-layout + - description: Configure Credentials, Deployment Mode etc. + elements: + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - if: showStorageSizeField - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - label: - text: Externally Managed? - schema: - $ref: schema#/properties/spec/properties/topology/properties/clickHouseKeeper/properties/externallyManaged + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: - elements: - - customClass: mt-10 - label: - text: labels.host - schema: - $ref: schema#/properties/spec/properties/topology/properties/clickHouseKeeper/properties/node/properties/host - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/spec/properties/topology/properties/clickHouseKeeper/properties/node/properties/port - type: input - if: isExternallyManaged|true - label: - text: Node - show_label: true - type: single-step-form - - elements: - - customClass: mt-10 - label: - text: Size - schema: - $ref: schema#/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/persistence/properties/size - type: input - - label: - text: Replicas - schema: - $ref: schema#/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/replicas - type: input - - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/clickHouseKeeper/spec - disabled: isMachineNotCustom|topology/clickHouseKeeper/spec - if: isMachineCustom|topology/clickHouseKeeper/spec - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/clickHouseKeeper/spec - disabled: isMachineNotCustom|topology/clickHouseKeeper/spec - if: isMachineCustom|topology/clickHouseKeeper/spec - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/topology/properties/clickHouseKeeper/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - if: isExternallyManaged|false - label: - text: Spec - show_label: true - type: single-step-form - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret + - init: + type: func + value: setMonitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - if: isToggleOn|monitoring - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|monitoring + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-clickhouse-editor-options/ui/functions.js b/charts/kubedbcom-clickhouse-editor-options/ui/functions.js index e6db92df11..800afcc2e9 100644 --- a/charts/kubedbcom-clickhouse-editor-options/ui/functions.js +++ b/charts/kubedbcom-clickhouse-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1011 +317,1025 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Standalone', 'Cluster'] - return validType.includes(modelPathValue) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function showReplicaField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Replicaset'] - return validType.includes(modelPathValue) -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = [] + return !validType.includes(modelPathValue) + } -function onModeChange({ model, getValue, watchDependency, commit }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - if (modelPathValue === 'Replicaset') { - commit('wizard/model$update', { - path: '/spec/replicas', - value: 3, - force: true, - }) - } else { - commit('wizard/model$update', { - path: '/spec/replicas', - value: 1, - force: true, - }) + function showReplicaField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Replicaset'] + return validType.includes(modelPathValue) } -} -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function onModeChange() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + if (modelPathValue === 'Replicaset') { + commit('wizard/model$update', { + path: '/spec/replicas', + value: 3, + force: true, + }) + } else { + commit('wizard/model$update', { + path: '/spec/replicas', + value: 1, + force: true, + }) + } + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getMongoDbVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, }, - }, - } + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + // keep only non deprecated versions + const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions -} + filteredMongoDbVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMongoDbVersions + } -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } } -} -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: comparePath, - value: memory, + path: commitPath, + value: val, force: true, }) - return memory - } else { + } + + function setMachineToCustom(type) { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } + } + + function updateAgentValue(val) { commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', force: true, }) + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} - -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (val === 'capz' && ifDedicated()) return true + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb]`, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } + + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { + commit('wizard/model$update', { + path: '/spec/admin/storageClasses/default', + value: storageClass, + force: true, }) - return val - } catch (e) { - console.log(e) - return [] } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, }) - url = url.slice(0, -1) } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val } catch (e) { console.log(e) - return [] } - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!getValue(model, `/spec/admin/databases/ClickHouse/mode/toggle`)) { + let defMode = getDefault('databases/ClickHouse/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/ClickHouse/mode/available') || [] + if (arr.length) defMode = arr[0] + } commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/mode', + value: defMode, force: true, }) } - } catch (e) { - console.log(e) - } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/ClickHouse/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/ClickHouse/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/ClickHouse/mode/available') || [] - if (arr.length) defMode = arr[0] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) - } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) - } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + setDiscriminatorValue('/bundleApiLoaded', true) } - setDiscriminatorValue('/bundleApiLoaded', true) -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` - commit('wizard/model$update', { - path: path, - value: returnArray[0], - force: true, - }) + return returnArray } - return returnArray -} - -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - const options = getValue(model, `/spec/admin/${type}/available`) || [] + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') + const options = getValue(model, `/spec/admin/${type}/available`) || [] - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } } -} -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) - } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, watchDependency, discriminator }, 'alert') - ) -} + function returnFalse() { + return false + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function clearArbiterHidden() { + commit('wizard/model$update', { + path: `/spec/arbiter/enabled`, + value: false, + force: true, + }) - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + commit('wizard/model$update', { + path: `/spec/hidden/enabled`, + value: false, + force: true, + }) } -} -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') } - } catch (e) { - console.log(e) } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } return [] } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, }) - } catch (e) { - console.log(e) } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function isExternallyManaged({ getValue, model, watchDependency }, expected) { - watchDependency('model#/spec/topology/clickHouseKeeper/externallyManaged') - const val = getValue(model, 'spec/topology/clickHouseKeeper/externallyManaged') - return (val && expected === 'true') || (!val && expected === 'false') -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } + + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -return { - isExternallyManaged, - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - showAdditionalSettings, - returnFalse, - initBundle, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - showStorageSizeField, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showStorageSizeField, - getResources, - getMongoDbVersions, - onCreateAuthSecretChange, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - showReplicaField, - onModeChange, - setBackup, - getDefault, + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } + + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } + + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } + + function isExternallyManaged(expected) { + // watchDependency('model#/spec/topology/clickHouseKeeper/externallyManaged') + const val = getValue(model, 'spec/topology/clickHouseKeeper/externallyManaged') + return (val && expected === 'true') || (!val && expected === 'false') + } + + return { + isExternallyManaged, + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + showAdditionalSettings, + returnFalse, + initBundle, + getNamespaces, + updateAlertValue, + getAdminOptions, + isToggleOn, + showAlerts, + getNodeTopology, + clearArbiterHidden, + showHidden, + isConfigDatabaseOn, + notEqualToDatabaseMode, + filterNodeTopology, + onAuthChange, + setMonitoring, + isMachineNotCustom, + isMachineCustom, + showIssuer, + showArbiter, + clearConfiguration, + showStorageSizeField, + onBackupSwitch, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + getResources, + getMongoDbVersions, + onCreateAuthSecretChange, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + showReplicaField, + onModeChange, + setBackup, + getDefault, + } } diff --git a/charts/kubedbcom-clickhouse-editor/ui/edit-ui.yaml b/charts/kubedbcom-clickhouse-editor/ui/edit-ui.yaml index 5cd4261774..cf5adf9349 100644 --- a/charts/kubedbcom-clickhouse-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-clickhouse-editor/ui/edit-ui.yaml @@ -1,352 +1,229 @@ -steps: -- form: - discriminator: - dbDetails: - default: false - type: boolean +type: multi-step-form +step: + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComClickHouseAutoscaler/spec/compute/clickhouse/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/resourceDiffPercentage - type: input - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/minAllowed/properties/memory - type: input - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/minAllowed - show_label: true - type: single-step-form - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/maxAllowed/properties/memory - type: input - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/maxAllowed - show_label: true - type: single-step-form - - fetch: setControlledResources|clickhouse - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/controlledResources - type: multiselect - label: - text: ClickHouse - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - computed: getDbDetails - if: returnFalse - type: input - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComClickHouseAutoscaler/spec/storage/clickhouse/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + elements: + # clickhouse mode + - type: block-layout + label: ClickHouse + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComClickHouseAutoscaler/spec/storage/clickhouse/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComClickHouseAutoscaler/spec/storage/clickhouse/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/upperBound - type: input - label: - text: ClickHouse - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.7.label -type: multi-step-form + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComClickHouseAutoscaler/spec/compute/clickhouse/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: Min Allowed + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/minAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/minAllowed/properties/memory + - type: block-layout + label: Max Allowed + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/maxAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|clickhouse + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/clickhouse/properties/controlledResources + + - type: block-layout + label: Node Topology + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler + elements: + - type: block-layout + showLabels: false + elements: + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: ClickHouse + showLabels: true + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComClickHouseAutoscaler/spec/storage/clickhouse/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComClickHouse/spec/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComClickHouseAutoscaler/spec/storage/clickhouse/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComClickHouseAutoscaler/spec/storage/clickhouse/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/storage/properties/clickhouse/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComClickHouseAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + \ No newline at end of file diff --git a/charts/kubedbcom-clickhouse-editor/ui/functions.js b/charts/kubedbcom-clickhouse-editor/ui/functions.js index 22ef13bf86..1c4344f943 100644 --- a/charts/kubedbcom-clickhouse-editor/ui/functions.js +++ b/charts/kubedbcom-clickhouse-editor/ui/functions.js @@ -1,3175 +1,445 @@ -// ************************* common functions ******************************************** -// eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -function isNotShardModeSelected({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComClickHouse/spec') - const hasShardTopology = getValue(model, '/resources/kubedbComClickHouse/spec/shardTopology') - return !hasShardTopology -} - -function isShardModeSelected({ model, getValue, watchDependency, commit }) { - const resp = !isNotShardModeSelected({ model, getValue, watchDependency }) - if (resp) { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - } - return resp -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} - -// ************************* Basic Info ********************************************** -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] - } -} - -// ************************* Auth Secret Field ****************************************** -function showAuthPasswordField({ model, getValue, watchDependency }) { - watchDependency('model#/resources') - const modelPathValue = getValue(model, '/resources') - return !!( - modelPathValue && - modelPathValue.secret && - modelPathValue.secret.metadata && - modelPathValue.secret.metadata.name && - !showAuthSecretField({ model, getValue, watchDependency }) - ) -} - -function showAuthSecretField({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComClickHouse/spec') - const modelPathValue = getValue(model, '/resources/kubedbComClickHouse/spec') - return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) -} - -function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { - const resp = - !showAuthSecretField({ model, getValue, watchDependency }) && - !showAuthPasswordField({ model, getValue, watchDependency }) - const secret = getValue(model, '/resources/secret_auth') - if (resp && !secret) { - commit('wizard/model$update', { - path: '/resources/secret_auth', - value: { - data: { - password: '', - }, - }, - force: true, - }) - } - return resp -} - -// ********************* Database Mode *********************** -function isNotStandaloneMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Standalone' -} - -function showCommonStorageClassAndSizeField({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(mode) -} -function setDatabaseMode({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/resources/kubedbComClickHouse/spec') - - watchDependency('model#/resources/kubedbComClickHouse/spec') - if (modelPathValue.shardTopology) { - return 'Sharded' - } else if (modelPathValue.replicaSet) { - return 'Replicaset' - } else { - return 'Standalone' - } -} - -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, model, getValue, watchDependency, discriminator }, - mode, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const databaseModeShard = getValue(discriminator, '/activeDatabaseMode') === 'Sharded' - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - storageClassList = resources - const path = - mode === 'shard' - ? '/resources/kubedbComClickHouse/spec/shardTopology/shard/storage/storageClassName' - : '/resources/kubedbComClickHouse/spec/storage/storageClassName' - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ getValue, commit, model, discriminator }) - return resources -} - -function setStorageClass({ getValue, commit, model, discriminator }) { - const deletionPolicy = getValue(model, 'resources/kubedbComClickHouse/spec/deletionPolicy') || '' - const suffix = '-retain' - let storageClass = '' - - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) - - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) - - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } - - const mode = getValue(discriminator, '/activeDatabaseMode') - - if (mode === 'Sharded') { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/shard/storage/storageClassName', - value: storageClass, - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, - force: true, - }) - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/storage') - } else { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/storage/storageClassName', - value: storageClass, - force: true, - }) - } -} - -function updateConfigServerStorageClass({ getValue, model, commit }) { - const storageClass = - getValue( - model, - '/resources/kubedbComClickHouse/spec/shardTopology/shard/storage/storageClassName', - ) || '' - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, - force: true, - }) -} - -function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - const modelSpec = getValue(model, '/resources/kubedbComClickHouse/spec') - if (mode === 'Sharded') { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/podTemplate') - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/configSecret') - - commit('wizard/model$delete', '/resources/secret_config') - - if (!modelSpec.shardTopology) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology', - value: { - configServer: { - replicas: 3, - storage: { - resources: { - requests: { - storage: '', - }, - }, - }, - }, - mongos: { - replicas: 2, - }, - shard: { - replicas: 3, - shards: 3, - storage: { - resources: { - requests: { - storage: '', - }, - }, - }, - }, - }, - force: true, - }) - } - } else if (mode === 'Replicaset') { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/shardTopology') - - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') - - if (!modelSpec.replicaSet) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/replicaSet', - value: { name: '' }, - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/replicas', - value: 3, - force: true, - }) - } - } else if (mode === 'Standalone') { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/shardTopology') - - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/replicas') - - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') - } -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} - -// ************************** TLS ******************************88 - -function setApiGroup() { - return 'cert-manager.io' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComClickHouse/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComClickHouse/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComClickHouse/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComClickHouse/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } - - if (!url) return [] - - try { - const resp = await axios.get(url) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComClickHouse/spec/clusterAuthMode') - return val || 'x509' -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComClickHouse/spec/sslMode') - return val || 'requireSSL' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/clusterAuthMode') - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/monitor/prometheus/exporter') - } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComClickHouse/spec/init/initialized') - watchDependency('model#/resources/kubedbComClickHouse/spec/init/initialized') - return !!initialized -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComClickHouse/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComClickHouse/spec/init/script') - - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} - -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComClickHouse/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComClickHouse/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue( - model, - '/resources/kubedbComClickHouse/spec/init/script/configMap/name', - ) - const secret = getValue( - model, - '/resources/kubedbComClickHouse/spec/init/script/secret/secretName', - ) - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/init/script/secret') - - if ( - !valueExists(model, getValue, '/resources/kubedbComClickHouse/spec/init/script/configMap') - ) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComClickHouse/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} - -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) - } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} - -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} - -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} - -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) - } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` - - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} - -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data - } - } catch (e) { - console.log(e) - } - return [] -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule backup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - - const coreKubestashComBackupConfiguration = getValue( - model, - '/resources/coreKubestashComBackupConfiguration', - ) - const kubeStashTarget = coreKubestashComBackupConfiguration?.spec?.target - - const mongoDB = getValue(model, '/resources/kubedbComClickHouse') - const mongoDbKind = mongoDB?.apiVersion?.split('/')?.at(0) - - let isKubeStash = false - if ( - mongoDB?.kind === kubeStashTarget?.kind && - mongoDB?.metadata?.name === kubeStashTarget?.name && - mongoDB?.metadata?.namespace === kubeStashTarget?.namespace && - mongoDbKind === kubeStashTarget?.apiGroup - ) { - isKubeStash = true - } - - const kubedbComClickHouseAnnotations = - getValue(model, '/resources/kubedbComClickHouse/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComClickHouseAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - isKubeStash, - } -} - -function deleteKubeDbComMongDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComClickHouse/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubeDbComMongDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComClickHouse/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComClickHouse annotation - deleteKubeDbComMongDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -async function initBackupData({ storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComClickHouse') - initialDbMetadata = objectCopy(dbResource.metadata) - initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check storageclass archiver annotation - if (initialArchiver) { - isArchiverAvailable = true - } else { - const storageClassName = dbResource?.spec?.storage?.storageClassName - const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` - try { - const resp = await axios.get(url) - const archAnnotation = resp.data?.metadata?.annotations - const annotationKeyToFind = `${resource}.${group}/archiver` - if (archAnnotation[annotationKeyToFind]) { - isArchiverAvailable = true - archiverObjectToCommit = { - ref: { - name: archAnnotation[annotationKeyToFind], - namespace: 'kubedb', - }, - } - } - } catch (e) { - console.log(e) - } - } - - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // set backup switch here - isBackupOn = !!config - - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends - - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` - - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions - } - - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, - } - - setDiscriminatorValue('isBackupDataLoaded', true) -} - -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} - -async function setBackupType() { - return 'BackupConfig' -} - -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - - if (dbResource?.spec?.topology && isArchiverAvailable) { - arr.push({ - description: 'Enable/Disable Archiver', - text: 'Archiver', - value: 'Archiver', - }) - } - return arr -} - -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), - force: true, - }) - } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse', - value: objectCopy(dbResource), - force: true, - }) -} - -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') - - return selectedType === type -} - -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations - - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} - -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} - -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} - -function onArchiverChange({ getValue, discriminator, commit, model, storeGet }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComClickHouse/spec/archiver' - if (archiverSwitch) { - commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, - }) - } else { - commit('wizard/model$delete', path) - } -} -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) - - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' - } - - commit('wizard/model$update', { - path: `/resources/kubedbComClickHouse/metadata/${type}`, - value: obj, - force: true, - }) -} - -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] - - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] - - commit('wizard/model$update', { - path: `/resources/kubedbComClickHouse/metadata/${type}`, - value: obj, - force: true, - }) -} - -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} - -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, - force: true, - }) - } -} - -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} - -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} - -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} - -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} - -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} - -function getNamespaceArray() { - return namespaceList -} - -// invoker form -function initBackupInvoker() { - return 'backupConfiguration' -} - -function initBlueprint() { - return 'create' -} -function initUsagePolicy() { - return 'Same' -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model, storeGet }) { - const kind = storeGet('/resource/layout/result/resource/kind') - const backupInvoker = getValue(discriminator, '/backupInvoker') - const annotations = getValue(model, '/resources/kubedbComClickHouse/metadata/annotations') - - // get name namespace labels to set in db resource when backup is not enabled initially - - if (backupInvoker === 'backupConfiguration') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: initialModel, - force: true, - }) - - if ( - !dbResource.metadata?.annotations?.['blueprint.kubestash.com/name'] && - !dbResource.metadata?.annotations?.['blueprint.kubestash.com/namespace'] - ) { - delete annotations['blueprint.kubestash.com/name'] - delete annotations['blueprint.kubestash.com/namespace'] - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/metadata/annotations', - value: annotations, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - if (!isBackupOn) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } - annotations['blueprint.kubestash.com/name'] = `${kind.toLowerCase()}-blueprint` - annotations['blueprint.kubestash.com/namespace'] = 'kubedb' - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/metadata/annotations', - value: annotations, - force: true, - }) - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComClickHouse/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = - getValue(model, '/resources/kubedbComClickHouse/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComClickHouse/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComClickHouse/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComClickHouse/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComClickHouse/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComClickHouse/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) - } - - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComClickHouse/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComClickHouse/spec/authSecret') - - return !authSecret -} +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') +// ************************* common functions ******************************************** +// eslint-disable-next-line no-empty-pattern +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + let autoscaleType = '' + let dbDetails = {} + + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue( + model, + '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name', + ) || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/clickhouses/${name}`, + ) + dbDetails = resp.data || {} + + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - if (stringPassword) { commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), + path: `/metadata/release/name`, + value: name, force: true, }) commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), + path: `/metadata/release/namespace`, + value: namespace, force: true, }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name`, + value: name, + force: true, }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] } -} -//////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// - -//////////////////// service monitor /////////////////// + function isKubedb() { + return !!storeGet('/route/params/actions') + } -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} + function isConsole() { + const isKube = isKubedb() -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, + path: '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/name', + value: modifiedName, force: true, }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/mongod.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' + return !isKube } - return 'use-existing-config' -} -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -//////////////////// custom config for sharded topology ///////////////// - -function setConfigurationSourceShard({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceShard') - if (src) return src - const value = getValue(model, '/resources/secret_shard_config') - return value ? 'create-new-config' : 'use-existing-config' -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setConfigurationSourceConfigServer({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceConfigServer') - if (src) return src - const value = getValue(model, '/resources/secret_configserver_config') - return value ? 'create-new-config' : 'use-existing-config' -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) -function setConfigurationSourceMongos({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceMongos') - if (src) return src - const value = getValue(model, '/resources/secret_mongos_config') - return value ? 'create-new-config' : 'use-existing-config' -} + const resources = (resp && resp.data && resp.data.items) || [] -function isSchemaOf(schema) { - if (schema === 'discriminator#/configurationSourceShard') { - return 'shard' - } else if (schema === 'discriminator#/configurationSourceConfigServer') { - return 'configserver' - } else { - return 'mongos' + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } -} -function disableConfigSourceOption({ - itemCtx, - discriminator, - getValue, - watchDependency, - elementUi, -}) { - watchDependency('discriminator#/configurationSourceShard') - watchDependency('discriminator#/configurationSourceConfigServer') - watchDependency('discriminator#/configurationSourceMongos') - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - if ( - itemCtx.value !== 'use-existing-config' && - itemCtx.value !== 'create-new-config' && - (configSrcShard === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcConfigServer === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcMongos === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret`) - ) { - return true - } - if ( - itemCtx.value === 'same-as-shard-config-secret' && - configSrcShard !== 'use-existing-config' && - configSrcShard !== 'create-new-config' - ) { - return true - } - if ( - itemCtx.value === 'same-as-configserver-config-secret' && - configSrcConfigServer !== 'use-existing-config' && - configSrcConfigServer !== 'create-new-config' - ) { - return true - } - if ( - itemCtx.value === 'same-as-mongos-config-secret' && - configSrcMongos !== 'use-existing-config' && - configSrcMongos !== 'create-new-config' - ) { - return true + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - return false -} -function onConfigurationSourceMongosChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceMongos') - const configSecretName = `${getValue(model, '/metadata/release/name')}-mongos-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_mongos_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_mongos_config') - if (!value) { + function onNamespaceChange() { + const namespace = getValue(model, '/metadata/release/namespace') + const agent = getValue(model, '/resources/kubedbComClickHouse/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/secret_mongos_config', - value: {}, + path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + value: [namespace], force: true, }) } - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/mongos/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'shard', 'mongos') - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'mongos') } -} -function onConfigurationSourceShardChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceShard') - const configSecretName = `${getValue(model, '/metadata/release/name')}-shard-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_shard_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_shard_config') - if (!value) { + function initMetadata() { + const dbName = + getValue( + model, + '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name', + ) || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/secret_shard_config', - value: {}, + path: '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/name', + value: modifiedName, force: true, }) - } - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/shard/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'shard') - } else if (configurationSource === 'same-as-mongos-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'mongos', 'shard') - } -} -function onConfigurationSourceConfigServerChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceConfigServer') - const configSecretName = `${getValue(model, '/metadata/release/name')}-configserver-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_configserver_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_configserver_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_configserver_config', - value: {}, - force: true, - }) - } - commit('wizard/model$update', { - path: '/resources/kubedbComClickHouse/spec/shardTopology/configServer/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceShard') - transferConfigSecret( - { commit, model, getValue }, - 'shard', - 'configserver', - configurationSourceReference, - ) - } else if (configurationSource === 'same-as-mongos-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceMongos') - transferConfigSecret( - { commit, model, getValue }, - 'mongos', - 'configserver', - configurationSourceReference, - ) + // delete the other type object from vuex wizard model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute', + ) } -} -function transferConfigSecret({ commit, model, getValue }, src, des) { - const isShardedMode = getValue(model, '/resources/kubedbComClickHouse/spec/shardTopology') - if (isShardedMode) { - commit('wizard/model$update', { - path: `/resources/kubedbComClickHouse/spec/shardTopology/${ - des === 'configserver' ? 'configServer' : des - }/configSecret/name`, - value: getValue( - model, - `/resources/kubedbComClickHouse/spec/shardTopology/${ - src === 'configserver' ? 'configServer' : src - }/configSecret/name`, - ), - force: true, - }) + async function fetchTopologyMachines() { + const instance = hasAnnotations() - commit('wizard/model$delete', `/resources/secret_${des}_config`) - } -} + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) -function onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - configType, - configSrc, - discriminatorPath, -) { - if (configSrc === 'create-new-config') { - const value = getValue(discriminator, discriminatorPath) - commit('wizard/model$update', { - path: `/resources/secret_${configType}_config/stringData/mongod.conf`, - value: value, - force: true, - }) + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - if (configSrcShard === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'shard') - } - if (configSrcConfigServer === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'configserver') - } - if (configSrcMongos === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'mongos') + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' } -} -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/mongod.conf') -} + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] -function setConfigurationShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/stringData/mongod.conf') - return value -} + return !!instance + } -function setConfigurationConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/stringData/mongod.conf') - return value -} + function setAllowedMachine(minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' -function setConfigurationMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/stringData/mongod.conf') - return value -} + if (minmax === 'min') return mn + else return mx + } -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/mongod.conf') - return atob(value) -} + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` -function setConfigurationFilesShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/data/mongod.conf') - return atob(value) -} + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) -function setConfigurationFilesConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/data/mongod.conf') - return atob(value) -} + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] -function setConfigurationFilesMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/data/mongod.conf') - return atob(value) -} + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComClickHouse/spec/configSecret') - commit( - 'wizard/model$delete', - '/resources/kubedbComClickHouse/spec/shardTopology/shard/configSecret', + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, ) - commit( - 'wizard/model$delete', - '/resources/kubedbComClickHouse/spec/shardTopology/configServer/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComClickHouse/spec/shardTopology/mongos/configSecret', - ) - commit('wizard/model$delete', '/resources/secret_config') - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') - } -} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + return dependantIndex === -1 ? machines : filteredMachine } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute/${type}` - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { + if (minMachine && maxMachine && instance !== minMaxMachine) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace', - value: namespace, + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: { ...annotations }, force: true, }) } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue( - model, - '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name', - ) && !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + function hasNoAnnotations() { + return !hasAnnotations() + } -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name') || - '' + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, + }) + return list + } - if (namespace && name) { + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/clickhouses/${name}`, - ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList } catch (e) { console.log(e) } + return [] } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') - - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length } - clearSpecModel({ commit }, verd) - return type === verd && spec -} -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/${autoscaleType}/cluster`, + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') ) } -} -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name') || - '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) + function setApplyToIfReady() { + return 'IfReady' + } - // delete the other type object from model - if (type === 'compute') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/storage', - ) - if (type === 'storage') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute', + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace', ) -} + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name', + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, ) - } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + const resources = (resp && resp.data && resp.data.items) || [] -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - return name + return { + text: name, + value: name, + } }) - return mappedList - } catch (e) { - console.log(e) } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) } - if (!isNaN(threshold)) { - threshold += 'pc' + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, - }) } } -} -function objectCopy(obj) { - const temp = JSON.stringify(obj) - return JSON.parse(temp) -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/clickhouseopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} - -return { - getOpsRequestUrl, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - isNotShardModeSelected, - isShardModeSelected, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - getMongoDbVersions, - showAuthPasswordField, - showAuthSecretField, - showNewSecretCreateField, - isNotStandaloneMode, - showCommonStorageClassAndSizeField, - setDatabaseMode, - getStorageClassNames, - setStorageClass, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComMongDbAnnotation, - addKubeDbComMongDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfigurationSourceShard, - setConfigurationSourceConfigServer, - setConfigurationSourceMongos, - isSchemaOf, - disableConfigSourceOption, - onConfigurationSourceMongosChange, - onConfigurationSourceShardChange, - onConfigurationSourceConfigServerChange, - transferConfigSecret, - onConfigSecretModelChange, - setConfiguration, - setConfigurationShard, - setConfigurationConfigServer, - setConfigurationMongos, - setConfigurationFiles, - setConfigurationFilesShard, - setConfigurationFilesConfigServer, - setConfigurationFilesMongos, - onSetCustomConfigChange, - getCreateNameSpaceUrl, - updateConfigServerStorageClass, - - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - getNamespaceArray, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, + return { + getDbDetails, + isKubedb, + isConsole, + getNamespaces, + isRancherManaged, + onNamespaceChange, + initMetadata, + fetchTopologyMachines, + setTrigger, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + setControlledResources, + fetchNodeTopology, + isNodeTopologySelected, + showOpsRequestOptions, + setApplyToIfReady, + getDbs, + handleUnit, + } } diff --git a/charts/kubedbcom-druid-editor-options/ui/create-ui.yaml b/charts/kubedbcom-druid-editor-options/ui/create-ui.yaml index 5451918561..1137edd35b 100644 --- a/charts/kubedbcom-druid-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-druid-editor-options/ui/create-ui.yaml @@ -1,479 +1,465 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Druid/versions + if: + type: function + name: isToggleOn|databases/Druid/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Druid/properties/versions/properties/default + type: select + - elements: + - elements: + - label: Storage size + schema: schema/properties/spec/properties/topology/properties/middleManagers/properties/persistence/properties/size + type: input + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/middleManagers/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/middleManagers/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/middleManagers + if: + type: function + name: isMachineCustom|topology/middleManagers + label: cpu + watcher: + func: setRequests|cpu|topology/middleManagers + paths: + - schema/properties/spec/properties/topology/properties/middleManagers/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/middleManagers/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/middleManagers + if: + type: function + name: isMachineCustom|topology/middleManagers + label: memory + watcher: + func: setRequests|memory|topology/middleManagers + paths: + - schema/properties/spec/properties/topology/properties/middleManagers/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/middleManagers/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Middle Managers + showLabels: true + type: block-layout + - elements: + - label: Storage size + schema: schema/properties/spec/properties/topology/properties/historicals/properties/persistence/properties/size + type: input + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/historicals/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/historicals/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/historicals + if: + type: function + name: isMachineCustom||topology/historicals + label: cpu + watcher: + func: setRequests|cpu|topology/historicals + paths: + - schema/properties/spec/properties/topology/properties/historicals/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/historicals/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/historicals + if: + type: function + name: isMachineCustom||topology/historicals + label: memory + watcher: + func: setRequests|memory|topology/historicals + paths: + - schema/properties/spec/properties/topology/properties/historicals/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/historicals/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Historicals + showLabels: true + type: block-layout + - elements: + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/brokers/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/brokers/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/brokers + if: + type: function + name: isMachineCustom|topology/brokers + label: cpu + watcher: + func: setRequests|cpu|topology/middleManagers + paths: + - schema/properties/spec/properties/topology/properties/brokers/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/brokers/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/brokers + if: + type: function + name: isMachineCustom|topology/brokers + label: memory + watcher: + func: setRequests|memory|topology/brokers + paths: + - schema/properties/spec/properties/topology/properties/brokers/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/brokers/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Brokers + showLabels: true + type: block-layout + - elements: + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/coordinators/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/coordinators/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/coordinators + if: + type: function + name: isMachineCustom|topology/coordinators + label: cpu + watcher: + func: setRequests|cpu|topology/middleManagers + paths: + - schema/properties/spec/properties/topology/properties/coordinators/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/coordinators/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/coordinators + if: + type: function + name: isMachineCustom|topology/coordinators + label: memory + watcher: + func: setRequests|memory|topology/coordinators + paths: + - schema/properties/spec/properties/topology/properties/coordinators/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/coordinators/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Coordinators + showLabels: true + type: block-layout + type: block-layout + - customClass: mt-10 + loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Deep Storage + options: + - s3 + - google + - azure + - hdfs + schema: schema/properties/spec/properties/deepStorage/properties/type + type: select + - loader: getSecrets + label: Config Secret + refresh: true + schema: schema/properties/spec/properties/deepStorage/properties/configSecret + type: select + - description: Configure Credentials, Deployment Mode etc. elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Druid/versions - if: isToggleOn|databases/Druid/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Druid/properties/versions/properties/default - type: select - elements: - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/middleManagers/properties/persistence/properties/size - type: input - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/middleManagers/properties/replicas - type: input - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/middleManagers/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/middleManagers - disabled: isMachineNotCustom|topology/middleManagers - if: isMachineCustom|topology/middleManagers - label: - text: labels.cpu - onChange: setRequests|cpu|topology/middleManagers - schema: - $ref: schema#/properties/spec/properties/topology/properties/middleManagers/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/middleManagers - disabled: isMachineNotCustom|topology/middleManagers - if: isMachineCustom|topology/middleManagers - label: - text: labels.memory - onChange: setRequests|memory|topology/middleManagers - schema: - $ref: schema#/properties/spec/properties/topology/properties/middleManagers/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.middleManagers - show_label: true - type: single-step-form - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/historicals/properties/persistence/properties/size - type: input - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/historicals/properties/replicas - type: input - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/historicals/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/historicals - disabled: isMachineNotCustom|topology/historicals - if: isMachineCustom||topology/historicals - label: - text: labels.cpu - onChange: setRequests|cpu|topology/historicals - schema: - $ref: schema#/properties/spec/properties/topology/properties/historicals/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/historicals - disabled: isMachineNotCustom|topology/historicals - if: isMachineCustom||topology/historicals - label: - text: labels.memory - onChange: setRequests|memory|topology/historicals - schema: - $ref: schema#/properties/spec/properties/topology/properties/historicals/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.historicals - show_label: true - type: single-step-form - - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/brokers/properties/replicas - type: input - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/brokers/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/brokers - disabled: isMachineNotCustom|topology/brokers - if: isMachineCustom|topology/brokers - label: - text: labels.cpu - onChange: setRequests|cpu|topology/middleManagers - schema: - $ref: schema#/properties/spec/properties/topology/properties/brokers/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/brokers - disabled: isMachineNotCustom|topology/brokers - if: isMachineCustom|topology/brokers - label: - text: labels.memory - onChange: setRequests|memory|topology/brokers - schema: - $ref: schema#/properties/spec/properties/topology/properties/brokers/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.brokers - show_label: true - type: single-step-form - - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinators/properties/replicas - type: input - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinators/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/coordinators - disabled: isMachineNotCustom|topology/coordinators - if: isMachineCustom|topology/coordinators - label: - text: labels.cpu - onChange: setRequests|cpu|topology/middleManagers - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinators/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/coordinators - disabled: isMachineNotCustom|topology/coordinators - if: isMachineCustom|topology/coordinators - label: - text: labels.memory - onChange: setRequests|memory|topology/coordinators - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinators/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.coordinators - show_label: true - type: single-step-form - type: single-step-form - - customClass: mt-10 - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - label: - text: labels.deepStorage + - label: Metadata Storage External + schema: schema/properties/spec/properties/metadataStorage/properties/externallyManaged + type: switch + - if: + type: function + name: isExternallyManaged|metadataStorage + label: Metadata Storage Type + watcher: + func: clearRefs|metadataStorage + paths: + - schema/properties/spec/properties/metadataStorage/properties/type options: - - s3 - - google - - azure - - hdfs - schema: - $ref: schema#/properties/spec/properties/deepStorage/properties/type + - text: MySQL + value: MySQL + - text: Postgres + value: Postgres + schema: schema/properties/spec/properties/metadataStorage/properties/type type: select - - fetch: getSecrets - label: - text: labels.configSecret + - loader: getAppBindings|mysql + if: + type: function + name: isMetadataStorageTypeEqualsTo|MySQL + label: MySQL + watcher: + func: onRefChange|metadataStorage + paths: + - temp/metadataStorage refresh: true - schema: - $ref: schema#/properties/spec/properties/deepStorage/properties/configSecret + validation: + type: required + schema: temp/metadataStorage type: select - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - metadataStorage: - default: {} - type: object - referSecret: - default: false - type: boolean - zookeeperRef: - default: {} - type: object - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - label: - text: labels.metadataStorage.external - schema: - $ref: schema#/properties/spec/properties/metadataStorage/properties/externallyManaged - type: switch - - if: isExternallyManaged|metadataStorage - label: - text: labels.metadataStorage.type - onChange: clearRefs|metadataStorage - options: - - text: MySQL - value: MySQL - - text: Postgres - value: Postgres - schema: - $ref: schema#/properties/spec/properties/metadataStorage/properties/type - type: select - - fetch: getAppBindings|mysql - if: isMetadataStorageTypeEqualsTo|MySQL - label: - text: labels.metadataStorage.mysql - onChange: onRefChange|metadataStorage - refresh: true - required: true - schema: - $ref: discriminator#/metadataStorage - type: select - - fetch: getAppBindings|postgres - if: isMetadataStorageTypeEqualsTo|Postgres - label: - text: labels.metadataStorage.postgres - onChange: onRefChange|metadataStorage - refresh: true - required: true - schema: - $ref: discriminator#/metadataStorage - type: select - - label: - text: labels.zookeeperRef.external - schema: - $ref: schema#/properties/spec/properties/zookeeperRef/properties/externallyManaged - type: switch - - fetch: getAppBindings|zookeeper - if: isExternallyManaged|zookeeperRef - label: - text: labels.zookeeperRef.zookeeper - onChange: onRefChange|zookeeperRef - refresh: true - required: true - schema: - $ref: discriminator#/zookeeperRef - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - loader: getAppBindings|postgres + if: + type: function + name: isMetadataStorageTypeEqualsTo|Postgres + label: Postgres + watcher: + func: onRefChange|metadataStorage + paths: + - temp/metadataStorage + refresh: true + validation: + type: required + schema: temp/metadataStorage + type: select + - label: Zookeeper External + schema: schema/properties/spec/properties/zookeeperRef/properties/externallyManaged + type: switch + - loader: getAppBindings|zookeeper + if: + type: function + name: isExternallyManaged|zookeeperRef + label: Zookeeper + watcher: + func: onRefChange|zookeeperRef + paths: + - temp/zookeeperRef + refresh: true + validation: + type: required + schema: temp/zookeeperRef + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - if: isToggleOn|expose - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|expose + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-druid-editor-options/ui/functions.js b/charts/kubedbcom-druid-editor-options/ui/functions.js index 7b6cff6d74..2392e85149 100644 --- a/charts/kubedbcom-druid-editor-options/ui/functions.js +++ b/charts/kubedbcom-druid-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -304,821 +306,836 @@ const machineList = [ 'db.r.24xlarge', ] -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('metadataStorage', {}) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('zookeeperRef', {}) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const secrets = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + const secrets = (resp && resp.data && resp.data.items) || [] - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - } else { - array = machineList - .map((machine) => { + return filteredSecrets + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) - commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, - force: true, - }) - commit('wizard/model$update', { - path: comparePath, - value: cpu, - force: true, - }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} - -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} - -function updateAlertValue({ commit, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} - -function getCreateNameSpaceUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue } - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) } -} - -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const isAlertToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'alert', - ) - return isMonitorEnabled && isAlertToggleEnabled -} - -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} - -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} - -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} - -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} - -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} - -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } -} -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, - }, - }, - } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, - ) - const resources = (resp && resp.data && resp.data.items) || [] - - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -function onRefChange({ discriminator, getValue, commit }, type) { - const ref = getValue(discriminator, `/${type}`) || {} - commit('wizard/model$update', { - path: `/spec/${type}/name`, - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: `/spec/${type}/namespace`, - value: ref.namespace || '', - force: true, - }) -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -function isExternallyManaged( - { getValue, model, watchDependency, commit, setDiscriminatorValue }, - type, -) { - watchDependency(`model#/spec/${type}/externallyManaged`) - const isManaged = getValue(model, `/spec/${type}/externallyManaged`) || false - if (!isManaged) clearRefs({ commit, setDiscriminatorValue }, type) - return isManaged -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) -function isMetadataStorageTypeEqualsTo({ getValue, model, watchDependency }, type) { - watchDependency('model#/spec/metadataStorage/type') - watchDependency('model#/spec/metadataStorage/externallyManaged') - const dbType = getValue(model, '/spec/metadataStorage/type') || '' - const isManaged = getValue(model, '/spec/metadataStorage/externallyManaged') || false - return isManaged && dbType === type -} + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) -function clearRefs({ commit, setDiscriminatorValue }, type) { - setDiscriminatorValue(`/${type}`, '') - commit('wizard/model$update', { - path: `/spec/${type}/name`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/spec/${type}/namespace`, - value: '', - force: true, - }) -} + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Druid/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Druid/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Druid/mode/available') || [] - if (arr.length) defMode = arr[0] - } + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const isAlertToggleEnabled = isToggleOn('alert') + return isMonitorEnabled && isAlertToggleEnabled + } + + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } + + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - if (!features.includes('tls')) { + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } + + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } + + function onAuthChange() { commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, + path: '/spec/authSecret/name', + value: '', force: true, }) - } - if (!features.includes('binding')) { commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, + path: '/spec/authSecret/password', + value: '', force: true, }) } - if (!features.includes('monitoring')) { + + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } + + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') + + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } + + async function getAppBindings(type) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const queryParams = { + filter: { + items: { + metadata: { name: null, namespace: null }, + spec: { type: null }, + }, + }, + } + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + queryParams, + ) + const resources = (resp && resp.data && resp.data.items) || [] + + const fileredResources = resources + .filter((item) => item.spec?.type === `kubedb.com/${type}`) + .map((item) => { + const name = item.metadata?.name || '' + const namespace = item.metadata?.namespace || '' + return { + text: `${namespace}/${name}`, + value: { + name: name, + namespace: namespace, + }, + } + }) + return fileredResources + } catch (e) { + console.log(e) + return [] + } + } + + function onRefChange(type) { + const ref = getValue(discriminator, `/${type}`) || {} commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', + path: `/spec/${type}/name`, + value: ref.name || '', force: true, }) commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', + path: `/spec/${type}/namespace`, + value: ref.namespace || '', force: true, }) } - if (!features.includes('backup')) { + + function isExternallyManaged(type) { + // watchDependency(`model#/spec/${type}/externallyManaged`) + const isManaged = getValue(model, `/spec/${type}/externallyManaged`) || false + if (!isManaged) clearRefs(type) + return isManaged + } + + function isMetadataStorageTypeEqualsTo(type) { + // watchDependency('model#/spec/metadataStorage/type') + // watchDependency('model#/spec/metadataStorage/externallyManaged') + const dbType = getValue(model, '/spec/metadataStorage/type') || '' + const isManaged = getValue(model, '/spec/metadataStorage/externallyManaged') || false + return isManaged && dbType === type + } + + function clearRefs(type) { + setDiscriminatorValue(`/${type}`, '') commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, + path: `/spec/${type}/name`, + value: '', force: true, }) commit('wizard/model$update', { - path: '/spec/backup/tool', + path: `/spec/${type}/namespace`, value: '', force: true, }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} - -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - return returnArray -} - -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!getValue(model, `/spec/admin/databases/Druid/mode/toggle`)) { + let defMode = getDefault('databases/Druid/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Druid/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + setDiscriminatorValue('/bundleApiLoaded', true) } - return options -} - -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (options.length === 0) { + return fetchOptions(type) + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + return options + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } + + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function returnFalse() { + return false + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - showAdditionalSettings, - returnFalse, - initBundle, - isVariantAvailable, - showAuthPasswordField, - getNamespaces, - getSecrets, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - isMachineNotCustom, - isMachineCustom, - updateAlertValue, - getCreateNameSpaceUrl, - setStorageClass, - showAlerts, - showIssuer, - onBackupSwitch, - setMonitoring, - onAuthChange, - isConfigDatabaseOn, - clearConfiguration, - getNodeTopology, - filterNodeTopology, - getAppBindings, - onRefChange, - isExternallyManaged, - isMetadataStorageTypeEqualsTo, - clearRefs, - isToggleOn, - getAdminOptions, - setBackup, - getDefault, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + showAdditionalSettings, + returnFalse, + initBundle, + isVariantAvailable, + showAuthPasswordField, + getNamespaces, + getSecrets, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + isMachineNotCustom, + isMachineCustom, + updateAlertValue, + getCreateNameSpaceUrl, + setStorageClass, + showAlerts, + showIssuer, + onBackupSwitch, + setMonitoring, + onAuthChange, + isConfigDatabaseOn, + clearConfiguration, + getNodeTopology, + filterNodeTopology, + getAppBindings, + onRefChange, + isExternallyManaged, + isMetadataStorageTypeEqualsTo, + clearRefs, + isToggleOn, + getAdminOptions, + setBackup, + getDefault, + } } diff --git a/charts/kubedbcom-druid-editor/ui/edit-ui.yaml b/charts/kubedbcom-druid-editor/ui/edit-ui.yaml index 1e1135a0dc..8fed0a2c3a 100644 --- a/charts/kubedbcom-druid-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-druid-editor/ui/edit-ui.yaml @@ -1,997 +1,860 @@ -steps: -- form: - discriminator: - dbDetails: - default: false - type: boolean +type: multi-step-form +step: + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: SelectDb - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: SelectType - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - discriminator: - topologyMachines: - default: [] - type: array + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType + options: + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/compute/brokers/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-brokers-max: - type: string - allowedMachine-brokers-min: - type: string + # brokers mode + - type: block-layout + label: Brokers + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers elements: - - computed: setAllowedMachine|brokers|min - disableUnselect: true - fetch: getMachines|brokers|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|brokers - schema: - $ref: discriminator#/properties/allowedMachine-brokers-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/minAllowed - show_label: true - type: single-step-form - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/maxAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|brokers|max - disableUnselect: true - fetch: getMachines|brokers|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|brokers - schema: - $ref: discriminator#/properties/allowedMachine-brokers-max - type: select - type: single-step-form - - fetch: setControlledResources|brokers - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/controlledResources - type: multiselect - label: - text: Brokers - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/compute/coordinators/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-coordinators-max: - type: string - allowedMachine-coordinators-min: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/compute/brokers/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-brokers-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|brokers|min + loader: + name: getMachines|brokers|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-brokers-max + watcher: + func: onMachineChange|brokers + paths: + - temp/properties/allowedMachine-brokers-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/minAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/minAllowed/properties/memory + - type: horizontal-layout + elements: + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-brokers-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|brokers|max + loader: + name: getMachines|brokers|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-brokers-min + watcher: + func: onMachineChange|brokers + paths: + - temp/properties/allowedMachine-brokers-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|brokers + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/brokers/properties/controlledResources + + # coordinators mode + - type: block-layout + label: Coordinators + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators elements: - - computed: setAllowedMachine|coordinators|min - disableUnselect: true - fetch: getMachines|coordinators|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|coordinators - schema: - $ref: discriminator#/properties/allowedMachine-coordinators-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/minAllowed - show_label: true - type: single-step-form - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/maxAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|coordinators|max - disableUnselect: true - fetch: getMachines|coordinators|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|coordinators - schema: - $ref: discriminator#/properties/allowedMachine-coordinators-max - type: select - type: single-step-form - - fetch: setControlledResources|coordinators - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/controlledResources - type: multiselect - label: - text: Coordinators - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/compute/historicals/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-historicals-max: - type: string - allowedMachine-historicals-min: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/compute/coordinators/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-coordinators-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|coordinators|min + loader: + name: getMachines|coordinators|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-coordinators-max + watcher: + func: onMachineChange|coordinators + paths: + - temp/properties/allowedMachine-coordinators-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-coordinators-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|coordinators|max + loader: + name: getMachines|coordinators|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-coordinators-min + watcher: + func: onMachineChange|coordinators + paths: + - temp/properties/allowedMachine-coordinators-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|coordinators + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/coordinators/properties/controlledResources + + # historicals mode + - type: block-layout + label: Historicals + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals elements: - - computed: setAllowedMachine|historicals|min - disableUnselect: true - fetch: getMachines|historicals|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|historicals - schema: - $ref: discriminator#/properties/allowedMachine-historicals-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|historicals|max - disableUnselect: true - fetch: getMachines|historicals|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|historicals - schema: - $ref: discriminator#/properties/allowedMachine-historicals-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|historicals - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/controlledResources - type: multiselect - label: - text: Historicals - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/compute/middleManagers/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-middleManagers-max: - type: string - allowedMachine-middleManagers-min: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/compute/historicals/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-historicals-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|historicals|min + loader: + name: getMachines|historicals|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-historicals-max + watcher: + func: onMachineChange|historicals + paths: + - temp/properties/allowedMachine-historicals-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-historicals-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|historicals|max + loader: + name: getMachines|historicals|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-historicals-min + watcher: + func: onMachineChange|historicals + paths: + - temp/properties/allowedMachine-historicals-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|historicals + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/historicals/properties/controlledResources + + # middleManagers mode + - type: block-layout + label: Middle Managers + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers elements: - - computed: setAllowedMachine|middleManagers|min - disableUnselect: true - fetch: getMachines|middleManagers|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|middleManagers - schema: - $ref: discriminator#/properties/allowedMachine-middleManagers-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|middleManagers|max - disableUnselect: true - fetch: getMachines|middleManagers|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|middleManagers - schema: - $ref: discriminator#/properties/allowedMachine-middleManagers-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|middleManagers - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/controlledResources - type: multiselect - label: - text: MiddleManagers - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers - show_label: true - type: single-step-form - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: OpsRequest Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.0.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/compute/middleManagers/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-middleManagers-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|middleManagers|min + loader: + name: getMachines|middleManagers|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-middleManagers-max + watcher: + func: onMachineChange|middleManagers + paths: + - temp/properties/allowedMachine-middleManagers-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-middleManagers-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|middleManagers|max + loader: + name: getMachines|middleManagers|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-middleManagers-min + watcher: + func: onMachineChange|middleManagers + paths: + - temp/properties/allowedMachine-middleManagers-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|middleManagers + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/middleManagers/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + - type: single-step-form + id: storage-autoscaler elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: SelectDb - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: SelectType - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/storage/historicals/trigger - label: - text: trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - type: block-layout + showLabels: false + elements: + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: Historicals + showLabels: true elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComDruidAutoscaler/spec/storage/historicals/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComDruidAutoscaler/spec/storage/historicals/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/upperBound - type: input - label: - text: Historicals - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals - show_label: true - type: single-step-form - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/storage/middleManagers/trigger - label: - text: trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/storage/historicals/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComDruid/spec/topology/historicals/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComDruidAutoscaler/spec/storage/historicals/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComDruidAutoscaler/spec/storage/historicals/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/historicals/properties/upperBound + - type: block-layout + label: MiddleManagers + showLabels: true elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComDruidAutoscaler/spec/storage/middleManagers/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComDruidAutoscaler/spec/storage/middleManagers/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/upperBound - type: input - label: - text: MiddleManagers - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers - show_label: true - type: single-step-form - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: OpsRequest Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.1.label -- form: - discriminator: - binding: - default: false - type: boolean + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComDruidAutoscaler/spec/storage/middleManagers/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComDruid/spec/topology/middleManagers/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComDruidAutoscaler/spec/storage/middleManagers/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComDruidAutoscaler/spec/storage/middleManagers/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/storage/properties/middleManagers/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComDruidAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + - type: single-step-form + id: monitoring elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComDruid/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComDruid/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComDruid/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/agent + isHorizontal: true + options: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComDruid/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComDruid/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComDruid/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComDruid/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComDruid/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -type: multi-step-form + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComDruid/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: single-step-form + id: binding + label: Gateway Binding + elements: + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-druid-editor/ui/functions.js b/charts/kubedbcom-druid-editor/ui/functions.js index 2c69984a80..1397b31a39 100644 --- a/charts/kubedbcom-druid-editor/ui/functions.js +++ b/charts/kubedbcom-druid-editor/ui/functions.js @@ -1,3434 +1,849 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx, setDiscriminatorValue }, discriminatorPath) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) - if (discriminatorPath) { - setDiscriminatorValue(discriminatorPath, { - ui: ui.data || {}, - language: language.data || {}, - functions, - }) - } + // storage - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function handleUnit(path, type = 'bound') { + console.log('handleUnit') + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } + } } -} -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + // compute -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + let autoscaleType = '' + let dbDetails = {} - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') || + '' - const resources = (resp && resp.data && resp.data.items) || [] + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/druids/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComRedisAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } -} -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} + function isConsole() { + const isKube = isKubedb() -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: namespace, + force: true, + }) + } + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + return !isKube + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const resources = (resp && resp.data && resp.data.items) || [] + + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - return ans -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function onNamespaceChange() { + const namespace = getValue(model, '/metadata/namespace') + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name', + ) + } + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + async function getDbs() { + // watchDependency('model#/metadata/namespace') + const namespace = getValue(model, '/metadata/namespace') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/druids`, + { + params: { filter: { items: { metadata: { name: null } } } }, }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } + ) - return ans -} + const resources = (resp && resp.data && resp.data.items) || [] -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) + commit('wizard/model$update', { + path: '/metadata/name', + value: modifiedName, + force: true, + }) + + // delete the other type object from model + if (type === 'compute') + commit('wizard/model$delete', '/resources/autoscalingKubedbComDruidAutoscaler/spec/storage') + if (type === 'storage') + commit('wizard/model$delete', '/resources/autoscalingKubedbComDruidAutoscaler/spec/compute') + } + + async function fetchTopologyMachines() { + const instance = hasAnnotations() + + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) + + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } } - }) -} + } -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComDruidAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + + return !!instance } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function getMachines(type, minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${type}-${depends}` -function returnTrue() { - return true -} + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) -function returnStringYes() { - return 'yes' -} + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] -function isDedicatedModeSelected({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComDruid/spec/topology') - isDedicatedSelected = getValue(model, '/resources/kubedbComDruid/spec/topology') + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - return !!isDedicatedSelected -} + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) -function isCombinedModeSelected({ model, getValue, watchDependency }) { - return !isDedicatedSelected({ model, getValue, watchDependency }) -} + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) -function isDiscriminatorEqualTo( - { discriminator, getValue, watchDependency }, - discriminatorPath, - value, -) { - watchDependency('discriminator#' + discriminatorPath) - const pathValue = getValue(discriminator, discriminatorPath) + return dependantIndex === -1 ? machines : filteredMachine + } - return value === pathValue -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComDruidAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } -function isAuthPluginNotSearchGuard({ discriminator, getValue, watchDependency, commit }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') - const pathValue = getValue(discriminator, '/selectedVersionAuthPlugin') + const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) + const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) + const minMaxMachine = `${minMachine},${maxMachine}` - if (!pathValue) return false + parsedInstance[type] = minMaxMachine + const instanceString = JSON.stringify(parsedInstance) + annotations['kubernetes.io/instance-type'] = instanceString - const ret = pathValue !== 'SearchGuard' && pathValue !== '' + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComDruidAutoscaler/spec/compute/${type}` - if (!ret) { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/dataWarm') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/dataHot') + if (minMachine && maxMachine && instance !== instanceString) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: annotations, + force: true, + }) + } } - return ret -} - -// required for outer form section. where discriminator can not be saved -async function showInternalUsersAndRolesMapping({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - commit, -}) { - watchDependency('model#/resources/kubedbComDruid/spec/disableSecurity') - watchDependency('model#/resources/kubedbComDruid/spec/version') - - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - const ret = - (dist === 'OpenDistro' || dist === 'SearchGuard') && - isSecurityEnabled({ model, getValue, watchDependency }) + function setAllowedMachine(type, minmax) { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComDruidAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } - if (ret) { - commit('wizard/showSteps$update', { - stepId: 'internal-users', - show: true, - }) + const machine = parsedInstance[type] || '' + const mx = machine?.includes(',') ? machine.split(',')[1] : '' + const mn = machine?.includes(',') ? machine.split(',')[0] : '' - commit('wizard/showSteps$update', { - stepId: 'roles-mapping', - show: true, - }) - } else { - commit('wizard/showSteps$update', { - stepId: 'internal-users', - show: false, - }) + if (minmax === 'min') return mn + else return mx + } - commit('wizard/showSteps$update', { - stepId: 'roles-mapping', - show: false, + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComDruidAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, }) + return list } - return ret -} - -// required for outer form section. where discriminator can not be saved -async function showSecureCustomConfig({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - commit, -}) { - watchDependency('model#/resources/kubedbComDruid/spec/version') - - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - const ret = dist === 'X-Pack' + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } - if (ret) { - commit('wizard/showSteps$update', { - stepId: 'secure-custom-config', - show: true, - }) - } else { - commit('wizard/showSteps$update', { - stepId: 'secure-custom-config', - show: false, - }) + function hasNoAnnotations() { + return !hasAnnotations() + } - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/secureConfigSecret') - commit('wizard/model$delete', '/resources/secret_secure_config') + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] } - return ret -} -// ************************* Basic Info ********************************************** + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComDruidAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComDruidAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } -async function getDruidVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function isKubedb() { + return !!storeGet('/route/params/actions') + } - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, authPlugin: null }, - }, - }, + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue(model, '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') && + !!getValue(discriminator, '/autoscalingType') + ) } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + function setApplyToIfReady() { + return 'IfReady' + } - const resources = (resp && resp.data && resp.data.items) || [] + // monitoring - // keep only non deprecated versions - const filteredDruidVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) || null + // watchDependency('model#' + modelPath) + return modelPathValue === value + } - filteredDruidVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredDruidVersions -} + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function isSecurityEnabled({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComDruid/spec/disableSecurity') - const value = getValue(model, '/resources/kubedbComDruid/spec/disableSecurity') - return !value -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -function onDisableSecurityChange({ model, getValue, commit }) { - const disableSecurity = getValue(model, '/resources/kubedbComDruid/spec/disableSecurity') + const resources = (resp && resp.data && resp.data.items) || [] - if (disableSecurity) { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/authSecret') - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/internalUsers') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/rolesMapping') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/tls') + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } } -} -async function onVersionChange({ - model, - getValue, - watchDependency, - axios, - storeGet, - commit, - setDiscriminatorValue, -}) { - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, + async function getNamespacedResourceList( axios, storeGet, - setDiscriminatorValue, - }) - - const isOpenDistro = dist === 'OpenDistro' - const isSearchGuard = dist === 'SearchGuard' - const isXpack = dist === 'X-Pack' - - if (!isOpenDistro && !isSearchGuard) { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/internalUsers') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/rolesMapping') - if (isXpack) { - removeCertificatesOfAliases({ model, getValue, commit }, ['admin']) - } - } else { - if (!isOpenDistro) { - const internalUsers = getValue(model, '/resources/kubedbComDruid/spec/internalUsers') - - if (internalUsers) { - Object.keys(internalUsers).map((key) => { - if (internalUsers[key]?.opendistroSecurityRoles) - delete internalUsers[key]?.opendistroSecurityRoles - }) - } + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/internalUsers', - value: internalUsers, - force: true, + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }) - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/dataHot') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/dataWarm') + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) } - if (!isSearchGuard) { - const internalUsers = getValue(model, '/resources/kubedbComDruid/spec/internalUsers') - if (internalUsers) { - Object.keys(internalUsers).map((key) => { - if (internalUsers[key]?.searchGuardRoles) delete internalUsers[key]?.searchGuardRoles - }) - } + return ans + } + + function removeCertificatesOfAliases(aliasesToRemove) { + const certificates = getValue(model, '/resources/kubedbComDruid/spec/tls/certificates') || [] + const updatedCertificates = certificates.filter((item) => !aliasesToRemove.includes(item.alias)) + commit('wizard/model$update', { + path: '/resources/kubedbComDruid/spec/tls/certificates', + value: updatedCertificates, + force: true, + }) + } + + /****** Monitoring *********/ + + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } + + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + console.log(configureStatus) + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/internalUsers', - value: internalUsers, + path: '/resources/kubedbComDruid/spec/monitor', + value: {}, force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComDruid/spec/monitor') } - if (!isXpack) { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/dataCold') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/dataContent') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/dataFrozen') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/ml') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology/transform') - } + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', + force: true, + }) } -} -function onEnableSSLChange({ model, getValue, commit }) { - const enabelSSL = getValue(model, '/resources/kubedbComDruid/spec/enableSSL') + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } - if (enabelSSL === false) { - removeCertificatesOfAliases({ model, getValue, commit }, [ - 'http', - 'archiver', - 'metrics-exporter', - ]) + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComDruid/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComDruid/spec/monitor/prometheus/exporter') + } } -} -function removeCertificatesOfAliases({ model, getValue, commit }, aliasesToRemove) { - const certificates = getValue(model, '/resources/kubedbComDruid/spec/tls/certificates') || [] - const updatedCertificates = certificates.filter((item) => !aliasesToRemove.includes(item.alias)) - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/tls/certificates', - value: updatedCertificates, - force: true, - }) -} + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } -/************************************* Database Secret Section ********************************************/ + // function onNamespaceChange({ commit, model, getValue }) { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComDruid/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComDruid/spec/authSecret') + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComDruid/spec/metadata/labels') - return !authSecret -} + const agent = getValue(model, '/resources/kubedbComDruid/spec/monitor/agent') -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) + } + } - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComDruid/spec/monitor/agent') -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} + if (!agent) { + removeCertificatesOfAliases({ model, getValue, commit }, ['metrics-exporter']) + } -function setAuthSecretPassword({ model, getValue, watchDependency, discriminator, commit }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) - const dist = getValue(discriminator, '/selectedVersionAuthPlugin') - if (dist) { - if (dist === 'X-Pack') { - const encodedPassword = getValue(model, '/resources/secret_elastic_cred/data/password') - commit('wizard/model$delete', '/resources/secret_admin_cred') - return encodedPassword ? decodePassword({}, encodedPassword) : '' + onNamespaceChange({ commit, model, getValue }) + onLabelChange({ commit, model, getValue }) + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } + } + + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` + + const isKube = !!storeGet('/route/params/actions') + + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/druidopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` + } + + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' } else { - const encodedPassword = getValue(model, '/resources/secret_admin_cred/data/password') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - return encodedPassword ? decodePassword({}, encodedPassword) : '' + return 'input' } } -} -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - const dist = getValue(discriminator, '/selectedVersionAuthPlugin') + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } - if (dist) { - if (stringPassword) { - if (dist === 'X-Pack') { + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) commit('wizard/model$update', { - path: '/resources/secret_elastic_cred/data/password', - value: encodePassword({}, stringPassword), - force: true, + path: 'temp/valueFrom/configMapKeyRef', + value: true, }) + if (isSecretTypeValueFrom()) commit('wizard/model$update', { - path: '/resources/secret_elastic_cred/data/username', - value: encodePassword({}, 'elastic'), - force: true, + path: 'temp/valueFrom/secretKeyRef', + value: true, }) - commit('wizard/model$delete', '/resources/secret_admin_cred') - } else { + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) commit('wizard/model$update', { - path: '/resources/secret_admin_cred/data/password', - value: encodePassword({}, stringPassword), - force: true, + path: 'temp/valueFrom/secretKeyRef', + value: false, }) + if (isConfigMapTypeValueFrom()) commit('wizard/model$update', { - path: '/resources/secret_admin_cred/data/username', - value: encodePassword({}, 'admin'), - force: true, + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, }) - commit('wizard/model$delete', '/resources/secret_elastic_cred') - } - } else { - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') } } -} -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] - } -} - -function showSecretSection({ model, getValue, watchDependency, storeGet }) { - const steps = storeGet('/wizard/configureOptions') - - return ( - !steps.includes('internal-users') && isSecurityEnabled({ model, getValue, watchDependency }) - ) -} - -// ********************* Database Mode *********************** -function isNotCombinedMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Combined' -} - -function setDatabaseMode({ model, getValue }) { - isDedicatedSelected = getValue(model, '/resources/kubedbComDruid/spec/topology') - if (isDedicatedSelected) { - return 'Dedicated' - } else { - return 'Combined' - } -} - -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, setDiscriminatorValue, getValue, model }, - path, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - - if (!path) { - setDiscriminatorValue('/storageClasses', resources) - } - storageClassList = resources - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ model, getValue, commit }, path) - return resources -} - -function setStorageClass({ model, getValue, commit }, path) { - const deletionPolicy = getValue(model, 'resources/kubedbComDruid/spec/deletionPolicy') || '' - let storageClass = getValue(model, path) || '' - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) - - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) - - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } - - if (storageClass && path) { - commit('wizard/model$update', { - path: path, - value: storageClass, - force: true, - }) - } -} - -function deleteDatabaseModePath({ discriminator, getValue, commit }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - if (mode === 'Dedicated') { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/maxUnavailable') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/podTemplate') - } else if (mode === 'Combined') { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/topology') - } -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - - return mode === value -} - -function getMaxUnavailableOptions({ model, getValue, watchDependency, commit, elementUi }, path) { - let prefixPath - if (path) { - prefixPath = path - } else { - const { $ref } = elementUi.schema || {} - const replacedPath = ($ref || '').replace( - 'schema#/properties/resources/properties/kubedbComDruid/properties/spec/properties/topology/properties/', - '', - ) - const dyn = replacedPath.split('/').shift() - prefixPath = `/resources/kubedbComDruid/spec/topology/${dyn}` - } - - watchDependency(`model#${prefixPath}/replicas`) - - const replicas = getValue(model, `${prefixPath}/replicas`) - const maxUnavailable = getValue(model, `${prefixPath}/maxUnavailable`) - - if (maxUnavailable > replicas) { - commit('wizard/model$update', { - path: `${prefixPath}/maxUnavailable`, - value: replicas, - force: true, - }) - } - - const options = [] - - for (let i = 0; i <= Math.min(replicas, 1000); i++) { - options.push(i) - } - return options -} - -function getStorageClassNamesFromDiscriminator( - { model, discriminator, getValue, watchDependency, commit }, - path, -) { - watchDependency('discriminator#/storageClasses') - const options = getValue(discriminator, '/storageClasses') || [] - - setStorageClass({ model, getValue, commit }, path) - - return options -} - -async function getSelectedVersionAuthPlugin( - { model, getValue, watchDependency, axios, storeGet, setDiscriminatorValue }, - path, -) { - watchDependency('model#/resources/kubedbComDruid/spec/version') - const version = getValue(model, '/resources/kubedbComDruid/spec/version') || '' - - const elasticVersions = await getDruidVersions( - { axios, storeGet }, - 'catalog.kubedb.com', - 'v1alpha1', - 'druidversions', - ) - - const selectedVersion = elasticVersions?.find((item) => item.value === version) - - const ret = selectedVersion?.spec?.authPlugin || '' - - if (path) { - setDiscriminatorValue(path, ret) - } - - return ret -} - -function onNodeSwitchFalse({ elementSchema, commit }) { - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - commit('wizard/model$delete', `/resources/kubedbComDruid/spec/topology/${node}`) -} - -function hasTopologyNode({ model, getValue, itemCtx }) { - const nodeValue = getValue(model, `/resources/kubedbComDruid/spec/topology/${itemCtx}`) - - return !nodeValue -} - -function hideNode({ itemCtx, discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') - const authPlugin = getValue(discriminator, '/selectedVersionAuthPlugin') - - let hiddenNodes = ['coordinating'] - - if (authPlugin === 'OpenDistro') { - hiddenNodes = ['coordinating', 'ml', 'dataCold', 'dataFrozen', 'dataContent', 'transform'] - } else if (authPlugin === 'SearchGuard') { - hiddenNodes = [ - 'coordinating', - 'ml', - 'dataWarm', - 'dataHot', - 'dataCold', - 'dataFrozen', - 'dataContent', - 'transform', - ] - } - - const verd = hiddenNodes.includes(itemCtx) - return verd -} - -function setInitialStatusFalse({ elementSchema }) { - const disableNodes = ['master', 'data', 'ingest'] - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - return !disableNodes.includes(node) -} - -function disableNode({ elementSchema }) { - const disableNodes = ['master', 'data', 'ingest'] - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - return disableNodes.includes(node) -} - -// ************************** Internal Users ******************************** - -const defaultUsers = [ - 'admin', - 'kibanaro', - 'kibanaserver', - 'logstash', - 'readall', - 'snapshotrestore', - 'metrics_exporter', -] - -function onInternalUsersChange({ discriminator, getValue, commit }) { - const users = getValue(discriminator, '/internalUsers') - - const internalUsers = {} - - if (users) { - users.forEach((item) => { - const { username, createCred, secretName, password, ...obj } = item - if (createCred === 'no') { - obj.secretName = secretName - commit('wizard/model$delete', `/resources/secret_${username}_cred`) - } else if (createCred === 'yes') { - if (password) { - commit('wizard/model$update', { - path: `/resources/secret_${username}_cred/data/password`, - value: encodePassword({}, password), - force: true, - }) - commit('wizard/model$update', { - path: `/resources/secret_${username}_cred/data/username`, - value: encodePassword({}, username), - force: true, - }) - } else { - commit('wizard/model$delete', `/resources/secret_${username}_cred`) - } - } - internalUsers[username] = obj - }) - } - - if (Object.keys(internalUsers).length) { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/internalUsers', - value: internalUsers, - force: true, - }) - } else { - // on initial call discriminator value is undefined - // to ignore model$delete for this case, - // users value checking is required, - // model$delete will be executed only if users value is not falsy value (empty array) - // and internalUsers is emptyObject - if (users) commit('wizard/model$delete', '/resources/kubedbComDruid/spec/internalUsers') - } -} - -function setInternalUsers({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/kubedbComDruid/spec/internalUsers') - const internalUsers = getValue(model, '/resources/kubedbComDruid/spec/internalUsers') - - const users = [] - - for (const item in internalUsers) { - internalUsers[item].username = item - const encodedPassword = getValue(model, `/resources/secret_${item}_cred/data/password`) - if (internalUsers[item].secretName) { - internalUsers[item].createCred = 'no' - } else { - if (encodedPassword) { - internalUsers[item].password = decodePassword({}, encodedPassword) - } - internalUsers[item].createCred = 'yes' - } - users.push(internalUsers[item]) - } - - setDiscriminatorValue('/internalUsers', users) - - return users -} - -function validateNewUser({ itemCtx }) { - if (defaultUsers.includes(itemCtx.username) && itemCtx.isCreate) { - return { isInvalid: true, message: "Can't use this username" } - } - return {} -} - -function disableUsername({ rootModel }) { - return defaultUsers.includes(rootModel && rootModel.username) -} - -function disableUserEdit({ itemCtx }) { - if (defaultUsers.includes(itemCtx.username)) { - return { isEditDisabled: false, isDeleteDisabled: true } - } - return {} -} - -async function isAuthPluginEqualTo( - { model, getValue, watchDependency, axios, storeGet, setDiscriminatorValue }, - authPlugin, -) { - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - return dist === authPlugin -} - -// internal user cred -function showPasswordCredSection({ rootModel, getValue, watchDependency }) { - watchDependency('rootModel#/createCred') - const createCred = getValue(rootModel, '/createCred') - - return createCred === 'yes' -} - -function showExistingCredSection({ rootModel, getValue, watchDependency }) { - return !showPasswordCredSection({ rootModel, getValue, watchDependency }) -} - -function disableRoleDeletion({ itemCtx, rootModel }) { - return itemCtx === 'admin' && rootModel.username === 'admin' -} - -// ************************** Roles Mapping ******************************** - -const defaultRoles = ['readall_and_monitor'] - -function onRolesMappingChange({ discriminator, getValue, commit }) { - const roles = getValue(discriminator, '/rolesMapping') - - const rolesMapping = {} - - if (roles) { - roles.forEach((item) => { - const { roleName, ...obj } = item - rolesMapping[roleName] = obj - }) - } - - if (Object.keys(rolesMapping).length) { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/rolesMapping', - value: rolesMapping, - force: true, - }) - } else { - // on initial call discriminator value is undefined - // to ignore model$delete for this case, - // roles value checking is required, - // model$delete will be executed only if roles value is not falsy value (empty array) - // and rolesMapping is emptyObject - if (roles) commit('wizard/model$delete', '/resources/kubedbComDruid/spec/rolesMapping') - } -} - -function setRolesMapping({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/kubedbComDruid/spec/rolesMapping') - const rolesMapping = getValue(model, '/resources/kubedbComDruid/spec/rolesMapping') - - const roles = [] - - for (const item in rolesMapping) { - rolesMapping[item].roleName = item - roles.push(rolesMapping[item]) - } - - setDiscriminatorValue('/rolesMapping', roles) - - return roles -} - -function disableRolesEdit({ itemCtx }) { - if (defaultRoles.includes(itemCtx.roleName)) { - return { isEditDisabled: false, isDeleteDisabled: true } - } - return {} -} - -function disableRoleName({ rootModel }) { - return defaultRoles.includes(rootModel && rootModel.roleName) -} - -function validateNewRole({ itemCtx }) { - if (defaultRoles.includes(itemCtx.roleName) && itemCtx.isCreate) { - return { isInvalid: true, message: "Can't use this role name" } - } - return {} -} - -function getInternalUsers({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComDruid/spec/internalUsers') - const internalUsers = getValue(model, '/resources/kubedbComDruid/spec/internalUsers') - - return Object.keys(internalUsers) -} - -function disableUserDeletion({ itemCtx, rootModel }) { - return itemCtx.value === 'metrics_exporter' && rootModel.roleName === 'readall_and_monitor' -} - -// ************************* Kernel Settings ********************************* - -function onCustomizeKernelSettingChange({ discriminator, getValue, commit }) { - const customizeKernelSettings = getValue(discriminator, '/customizeKernelSettings') - - if (customizeKernelSettings === 'no') { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/kernelSettings') - } else if (customizeKernelSettings === 'disable') { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/kernelSettings', - value: {}, - force: true, - }) - } -} - -// ************************** TLS ******************************************* - -function setApiGroup() { - return 'cert-manager.io' -} - -function setApiGroupEdit({ model, getValue }) { - const kind = getValue(model, '/resources/kubedbComDruid/spec/tls/issuerRef/kind') - const name = getValue(model, '/resources/kubedbComDruid/spec/tls/issuerRef/name') - return kind && name ? 'cert-manager.io' : '' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComDruid/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComDruid/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComDruid/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComDruid/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } - - try { - const resp = await axios.get(url) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComDruid/spec/clusterAuthMode') - return val || 'x509' -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComDruid/spec/sslMode') - return val || 'requireSSL' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/clusterAuthMode') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/sslMode') - } -} - -async function showTlsRecommendation({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/issuers` - - try { - await axios.get(url, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - return false - } catch (err) { - // if any error response status is 404 or not - if (err.response && err.response.status === 404) { - resp = false - } - console.log(err) - return true - } -} - -async function getAliasOptions({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, -}) { - watchDependency('model#/resources/kubedbComDruid/spec/enableSSL') - watchDependency('model#/resources/kubedbComDruid/spec/monitor') - - const enableSSL = getValue(model, '/resources/kubedbComDruid/spec/enableSSL') - const monitor = getValue(model, '/resources/kubedbComDruid/spec/monitor') - const authPlugin = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - - // always include transport cert alias - const aliases = ['transport'] - - if (authPlugin !== 'X-Pack') { - aliases.push('admin') - } - - if (enableSSL) { - aliases.push('http') - aliases.push('archiver') - if (monitor) { - aliases.push('metrics-exporter') - } - } - - return aliases -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/monitor/prometheus/exporter') - } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComDruid/spec/init/initialized') - watchDependency('model#/resources/kubedbComDruid/spec/init/initialized') - return !!initialized -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComDruid/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComDruid/spec/init/script') - - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} - -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComDruid/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComDruid/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComDruid/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComDruid/spec/init/script/secret/secretName') - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/init/script/secret') - - if (!valueExists(model, getValue, '/resources/kubedbComDruid/spec/init/script/configMap')) { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComDruid/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} - -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) - } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule bakcup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComDruidAnnotations = - getValue(model, '/resources/kubedbComDruid/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComDruidAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - } -} - -function deleteKubedbComDruidDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComDruid/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubedbComDruidDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComDruid/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComDruid annotation - deleteKubedbComDruidDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -// invoker form -async function initBackupInvoker({ getValue, model, storeGet, commit, axios }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - const apiGroup = getValue(model, '/metadata/resource/group') - let kind = getValue(model, '/metadata/resource/kind') - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const name = storeGet('/route/params/name') - const namespace = storeGet('/route/query/namespace') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - let labels = {} - - const sessions = getValue(model, '/resources/coreKubestashComBackupConfiguration/spec/sessions') - sessions[0].repositories[0].name = name - sessions[0].repositories[0].directory = `/${name}` - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/spec/sessions', - value: sessions, - force: true, - }) - - const url = `clusters/${username}/${clusterName}/proxy/${group}/${version}/namespaces/${namespace}/${resource}/${name}` - - try { - const resp = await axios.get(url) - labels = resp.data.metadata.labels - kind = resp.data.kind - } catch (e) { - console.log(e) - } - - commit('wizard/model$update', { - path: '/metadata/release', - value: { - labels: labels, - name: name, - namespace: namespace, - }, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/metadata', - value: { - labels: labels, - name: name, - namespace: namespace, - }, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/spec/target', - value: { - apiGroup: apiGroup, - kind: kind, - name: name, - namespace: namespace, - }, - force: true, - }) - - let isStashPresetEnable = false - try { - const url = `/clusters/${username}/${clusterName}/proxy/ui.k8s.appscode.com/v1alpha1/features` - const resp = await axios.get(url) - const stashFeature = resp.data.items.filter((item) => { - return item.metadata.name === 'stash-presets' - }) - if (stashFeature[0].status?.enabled) { - isStashPresetEnable = true - } - } catch (e) { - console.log(e) - } - let schedule = '' - let storageRefName = '' - let storageRefNamespace = '' - let retentionPolicyName = '' - let retentionPolicyNamespace = '' - let encryptionSecretName = '' - let encryptionSecretNamespace = '' - - if (isStashPresetEnable) { - try { - const url = `clusters/${username}/${clusterName}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/stash-presets` - const resp = await axios.get(url) - schedule = resp.data.spec.values.spec.backup.kubestash.schedule - storageRefName = resp.data.spec.values.spec.backup.kubestash.storageRef.name - storageRefNamespace = resp.data.spec.values.spec.backup.kubestash.storageRef.namespace - retentionPolicyName = resp.data.spec.values.spec.backup.kubestash.retentionPolicy.name - retentionPolicyNamespace = - resp.data.spec.values.spec.backup.kubestash.retentionPolicy.namespace - encryptionSecretName = resp.data.spec.values.spec.backup.kubestash.encryptionSecret.name - encryptionSecretNamespace = - resp.data.spec.values.spec.backup.kubestash.encryptionSecret.namespace - } catch (e) { - console.log(e) - } - } - setInitSchedule( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions/', - schedule, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'storageRef', - 'namespace', - storageRefNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'storageRef', - 'name', - storageRefName, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'retentionPolicy', - 'namespace', - retentionPolicyNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'retentionPolicy', - 'name', - retentionPolicyName, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions', - 'encryptionSecret', - 'namespace', - encryptionSecretNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions', - 'encryptionSecret', - 'name', - encryptionSecretName, - ) - - if (stashAppscodeComBackupConfiguration) return 'backupConfiguration' - else if (isBluePrint) return 'backupBlueprint' - else return undefined -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model }) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - - if (backupInvoker === 'backupConfiguration') { - // delete annotation and create backup config object - deleteKubedbComDruidDbAnnotation(getValue, model, commit) - const dbName = getValue(model, '/metadata/release/name') - - if (!valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - // delete backup configuration object and create the annotation - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - addKubedbComDruidDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - '', - ) - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComDruid/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubedbComDruidDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubedbComDruidDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComDruid/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComDruid/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComDruid/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComDruid/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComDruid/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComDruid/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_user_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComDruid/spec/monitor/agent') - - if (!agent) { - removeCertificatesOfAliases({ model, getValue, commit }, ['metrics-exporter']) - } - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -//////////////////// service monitor /////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_user_config') - commit('wizard/model$delete', '/resources/config_secret') - } else { - const value = getValue(model, '/resources/secret_user_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_user_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_user_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setConfigFiles({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/secret_user_config/stringData') - const configFiles = getValue(model, '/resources/secret_user_config/stringData') - - const files = [] - - for (const item in configFiles) { - const obj = {} - obj.key = item - obj.value = configFiles[item] - files.push(obj) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } - setDiscriminatorValue('/configFiles', files) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - return files -} - -function onConfigFilesChange({ discriminator, getValue, commit }) { - const files = getValue(discriminator, '/configFiles') - - const configFiles = {} - - if (files) { - files.forEach((item) => { - const { key, value } = item - configFiles[key] = value + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - } - - commit('wizard/model$update', { - path: '/resources/secret_user_config/stringData', - value: configFiles, - force: true, - }) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_user_config') - } -} - -function initSetCustomConfig({ model, getValue }) { - const configSecret = getValue(model, '/resources/kubedbComDruid/spec/configSecret/name') - - if (configSecret) return 'yes' - else return 'no' -} - -//////////////////// secret custom config ///////////////// -function onSecretConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_secure_config') - } else { - const value = getValue(model, '/resources/secret_secure_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_secure_config', - value: {}, - force: true, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) } - const configSecretName = `${getValue(model, '/metadata/release/name')}-secure-config` - commit('wizard/model$update', { - path: '/resources/kubedbComDruid/spec/secureConfigSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function setSecretConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_secure_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigFiles({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/secret_secure_config/stringData') - const configFiles = getValue(model, '/resources/secret_secure_config/stringData') - - const files = [] - - for (const item in configFiles) { - const obj = {} - obj.key = item - obj.value = configFiles[item] - files.push(obj) - } - - setDiscriminatorValue('/configFiles', files) - - return files -} -function onSecretConfigFilesChange({ discriminator, getValue, commit }) { - const files = getValue(discriminator, '/configFiles') - - const configFiles = {} - - if (files) { - files.forEach((item) => { - const { key, value } = item - configFiles[key] = value + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - commit('wizard/model$update', { - path: '/resources/secret_secure_config/stringData', - value: configFiles, - force: true, - }) -} - -function onSetSecretCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setSecretCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComDruid/spec/secureConfigSecret') - commit('wizard/model$delete', '/resources/secret_secure_config') - } -} - -function initSetSecureCustomConfig({ model, getValue }) { - const configSecret = getValue(model, '/resources/kubedbComDruid/spec/secureConfigSecret/name') - - if (configSecret) return 'yes' - else return 'no' -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/druidopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComDruid/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} + if (!configMapName) return [] -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) - } -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + const configMaps = (resp && resp.data && resp.data.data) || {} -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` - - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} - -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - data = data.map((ele) => ele.metadata.name) - return data - } - } catch (e) { - console.log(e) - } - return [] -} - -function initBlueprint() { - return 'create' -} -function initUsagePolicy() { - return 'Same' -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - discriminatorName, -) { - watchDependency(`model#/${modelPath}`) - const session = getValue(model, modelPath) - return session[0].scheduler.schedule -} - -////////////////// auto scaler ////////////// -let autoscaleType = '' -let dbDetails = {} -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) - - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: namespace, - force: true, - }) + return configMapKeys + } catch (e) { + console.log(e) + return [] } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/metadata/namespace') - const namespace = getValue(model, '/metadata/namespace') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/druids`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -async function getDbDetails({ setDiscriminatorValue, commit, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/druids/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) - } - } - - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComRedisAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ axios, storeGet, watchDependency, model, getValue, commit }, type) { - watchDependency('discriminator#/dbDetails') - - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else verd = 'standalone' - clearSpecModel({ commit }, verd) - return type === verd && spec -} - -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'node') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComDruidAutoscaler/spec/${autoscaleType}/data`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComDruidAutoscaler/spec/${autoscaleType}/ingest`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComDruidAutoscaler/spec/${autoscaleType}/master`, - ) - } else if (dbtype === 'topology') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComDruidAutoscaler/spec/${autoscaleType}/node`, - ) - } -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComDruidAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComDruidAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue(model, '/metadata/namespace') - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name', - ) - } -} - -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComDruidAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} - -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComDruidAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComDruidAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComDruidAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} + const secrets = (resp && resp.data && resp.data.items) || [] -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, + + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] } } -} -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComDruidBinding') - return isExposeBinding -} + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComDruid/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -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 labels = getValue(model, '/resources/kubedbComDruid/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'DruidBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { - name: dbName, - namespace: dbNamespace, - }, - }, - } + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - if (value) { - await commit('wizard/model$update', { - path: '/resources/catalogAppscodeComDruidBinding', - value: bindingValues, - force: true, - }) - } else { - await commit('wizard/model$delete', '/resources/catalogAppscodeComDruidBinding') - } -} + if (!secretName) return [] -function setMetadata({ storeGet, mode, commit }) { - const dbname = storeGet('/route/params/name') || '' - const namespace = storeGet('/route/query/namespace') || '' - if (mode === 'standalone-step') { - commit('wizard/model$update', { - path: '/metadata/release/name', - value: dbname, - force: true, - }) - commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, - force: true, - }) - } -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + const secret = (resp && resp.data && resp.data.data) || {} - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + return secretKeys } catch (e) { console.log(e) return [] } } -} -function setAllowedMachine({ model, getValue }, type, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComDruidAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function returnFalse() { + return false } - const machine = parsedInstance[type] || '' - const mx = machine?.includes(',') ? machine.split(',')[1] : '' - const mn = machine?.includes(',') ? machine.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, type, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${type}-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }, type) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComDruidAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComDruidAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value } - const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) - const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) - const minMaxMachine = `${minMachine},${maxMachine}` - - parsedInstance[type] = minMaxMachine - const instanceString = JSON.stringify(parsedInstance) - annotations['kubernetes.io/instance-type'] = instanceString - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComDruidAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== instanceString) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + return { + returnFalse, + handleUnit, + getDbDetails, + isConsole, + getNamespaces, + isRancherManaged, + onNamespaceChange, + getDbs, + initMetadata, + fetchTopologyMachines, + hasAnnotations, + getMachines, + onMachineChange, + setAllowedMachine, + setControlledResources, + setTrigger, + hasNoAnnotations, + fetchNodeTopology, + isNodeTopologySelected, + isKubedb, + showOpsRequestOptions, + setApplyToIfReady, + isEqualToModelPathValue, + getResources, + getNamespacedResourceList, + removeCertificatesOfAliases, + showMonitoringSection, + onEnableMonitoringChange, + onLabelChange, + onAgentChange, + showCustomizeExporterSection, + onCustomizeExporterChange, + isValueExistInModel, + setValueFrom, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + getOpsRequestUrl, + setValueFromDbDetails, } } - -return { - setMetadata, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - isDedicatedModeSelected, - isCombinedModeSelected, - isDiscriminatorEqualTo, - isAuthPluginNotSearchGuard, - showInternalUsersAndRolesMapping, - showSecureCustomConfig, - getDruidVersions, - isSecurityEnabled, - onDisableSecurityChange, - onVersionChange, - onEnableSSLChange, - removeCertificatesOfAliases, - setDatabaseMode, - getStorageClassNames, - getStorageClassNamesFromDiscriminator, - deleteDatabaseModePath, - isEqualToDatabaseMode, - getSelectedVersionAuthPlugin, - onNodeSwitchFalse, - hasTopologyNode, - hideNode, - disableNode, - setInitialStatusFalse, - onInternalUsersChange, - disableRoleDeletion, - setInternalUsers, - validateNewUser, - disableUsername, - disableUserEdit, - isAuthPluginEqualTo, - showExistingCredSection, - showPasswordCredSection, - onRolesMappingChange, - setRolesMapping, - disableRolesEdit, - disableRoleName, - validateNewRole, - disableUserDeletion, - onCustomizeKernelSettingChange, - getInternalUsers, - setApiGroup, - setApiGroupEdit, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - showTlsRecommendation, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubedbComDruidDbAnnotation, - addKubedbComDruidDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - setAuthSecretPassword, - onAuthSecretPasswordChange, - showSecretSection, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - setConfigurationSource, - getMaxUnavailableOptions, - setConfigFiles, - onConfigFilesChange, - onSetCustomConfigChange, - onSecretConfigurationSourceChange, - setSecretConfigurationSource, - setSecretConfigFiles, - onSecretConfigFilesChange, - onSetSecretCustomConfigChange, - initSetCustomConfig, - initSetSecureCustomConfig, - getOpsRequestUrl, - getCreateNameSpaceUrl, - isVariantAvailable, - setStorageClass, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, -} diff --git a/charts/kubedbcom-elasticsearch-editor-options/ui/create-ui.yaml b/charts/kubedbcom-elasticsearch-editor-options/ui/create-ui.yaml index 9fc3d274cf..9a9e6f1a74 100644 --- a/charts/kubedbcom-elasticsearch-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-elasticsearch-editor-options/ui/create-ui.yaml @@ -1,485 +1,456 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Elasticsearch/versions - if: isToggleOn|databases/Elasticsearch/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Elasticsearch/properties/versions/properties/default - type: select - - computed: getDefault|databases/Elasticsearch/mode - fetch: getAdminOptions|databases/Elasticsearch/mode - hasDescription: true - if: isToggleOn|databases/Elasticsearch/mode - label: - text: labels.database.mode - schema: - $ref: schema#/properties/spec/properties/mode - type: radio +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Elasticsearch/versions + if: + type: function + name: isToggleOn|databases/Elasticsearch/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Elasticsearch/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Elasticsearch/mode + loader: getAdminOptions|databases/Elasticsearch/mode + if: + type: function + name: isToggleOn|databases/Elasticsearch/mode + label: Database mode + isHorizontal: true + schema: schema/properties/spec/properties/mode + type: radio + - elements: + - label: Replicaset number + schema: schema/properties/spec/properties/replicas + type: input + if: + type: function + name: isEqualToModelPathValue|Combined|/spec/mode + type: block-layout + - elements: - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - label: Master nodes + type: label-element + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/master/properties/replicas type: input - if: isEqualToModelPathValue|Combined|/spec/mode - type: single-step-form - - elements: - elements: - - label: - text: labels.master_nodes - type: label-element - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/master/properties/replicas + - label: Storage size + schema: schema/properties/spec/properties/topology/properties/master/properties/persistence/properties/size type: input - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/master/properties/persistence/properties/size - type: input - schema: - $ref: schema#/properties/spec/properties/topology/properties/master/properties/persistence - type: single-step-form - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/master/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/master - disabled: isMachineNotCustom|topology/master - if: isMachineCustom|topology/master - label: - text: labels.cpu - onChange: setRequests|cpu|topology/master - schema: - $ref: schema#/properties/spec/properties/topology/properties/master/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/master - disabled: isMachineNotCustom|topology/master - if: isMachineCustom|topology/master - label: - text: labels.memory - onChange: setRequests|memory|topology/master - schema: - $ref: schema#/properties/spec/properties/topology/properties/master/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/spec/properties/topology/properties/master - type: single-step-form + type: block-layout - elements: - - label: - text: labels.data_nodes - type: label-element - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/replicas + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/master/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/master + if: + type: function + name: isMachineCustom|topology/master + label: cpu + watcher: + func: setRequests|cpu|topology/master + paths: + - schema/properties/spec/properties/topology/properties/master/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/master/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/persistence/properties/size - type: input - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/persistence - type: single-step-form - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/data - disabled: isMachineNotCustom|topology/data - if: isMachineCustom|topology/data - label: - text: labels.cpu - onChange: setRequests|cpu|topology/data - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/data - disabled: isMachineNotCustom|topology/data - if: isMachineCustom|topology/data - label: - text: labels.memory - onChange: setRequests|memory|topology/data - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/spec/properties/topology/properties/data - type: single-step-form - - elements: - - label: - text: labels.ingest_nodes - type: label-element - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/ingest/properties/replicas + - init: + type: func + value: setLimits|memory|topology/master + if: + type: function + name: isMachineCustom|topology/master + label: memory + watcher: + func: setRequests|memory|topology/master + paths: + - schema/properties/spec/properties/topology/properties/master/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/master/properties/podResources/properties/resources/properties/requests/properties/memory type: input - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/ingest/properties/persistence/properties/size - type: input - schema: - $ref: schema#/properties/spec/properties/topology/properties/ingest/properties/persistence - type: single-step-form - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/ingest/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/ingest - disabled: isMachineNotCustom|topology/ingest - if: isMachineCustom|topology/ingest - label: - text: labels.cpu - onChange: setRequests|cpu|topology/ingest - schema: - $ref: schema#/properties/spec/properties/topology/properties/ingest/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/ingest - disabled: isMachineNotCustom|topology/ingest - if: isMachineCustom|topology/ingest - label: - text: labels.memory - onChange: setRequests|memory|topology/ingest - schema: - $ref: schema#/properties/spec/properties/topology/properties/ingest/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/spec/properties/topology/properties/ingest - type: single-step-form - if: isEqualToModelPathValue|Topology|/spec/mode - schema: - $ref: schema#/properties/spec/properties/topology - type: single-step-form + label: Machine_profile + showLabels: true + type: block-layout + type: block-layout - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + - label: Data nodes + type: label-element + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/data/properties/replicas type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + - elements: + - label: Storage size + schema: schema/properties/spec/properties/topology/properties/data/properties/persistence/properties/size + type: input + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/data + if: + type: function + name: isMachineCustom|topology/data + label: cpu + watcher: + func: setRequests|cpu|topology/data + paths: + - schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/data + if: + type: function + name: isMachineCustom|topology/data + label: memory + watcher: + func: setRequests|memory|topology/data + paths: + - schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine_profile + showLabels: true + type: block-layout + type: block-layout + - elements: + - label: Ingest nodes + type: label-element + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/ingest/properties/replicas type: input - if: isEqualToModelPathValue|Combined|/spec/mode - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - elements: + - label: Storage size + schema: schema/properties/spec/properties/topology/properties/ingest/properties/persistence/properties/size + type: input + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/ingest/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/ingest + if: + type: function + name: isMachineCustom|topology/ingest + label: cpu + watcher: + func: setRequests|cpu|topology/ingest + paths: + - schema/properties/spec/properties/topology/properties/ingest/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/ingest/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/ingest + if: + type: function + name: isMachineCustom|topology/ingest + label: memory + watcher: + func: setRequests|memory|topology/ingest + paths: + - schema/properties/spec/properties/topology/properties/ingest/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/ingest/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine_profile + showLabels: true + type: block-layout + type: block-layout + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - if: isEqualToModelPathValue|Combined|/spec/mode - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: isEqualToModelPathValue|Combined|/spec/mode + label: Machine_profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: isEqualToModelPathValue|Combined|/spec/mode + label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + if: + type: function + name: isToggleOn|monitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring + type: switch + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - if: + type: function + name: isToggleOn|tls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - if: isToggleOn|monitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + type: block-layout + - elements: + - label: Disable Defaults + schema: schema/properties/spec/properties/kernelSettings/properties/disableDefaults type: switch - - elements: - - if: isToggleOn|tls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - elements: - - if: isToggleOn|expose - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - type: single-step-form - - elements: - - label: - text: labels.disableDefaults - schema: - $ref: schema#/properties/spec/properties/kernelSettings/properties/disableDefaults - type: switch - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-elasticsearch-editor-options/ui/functions.js b/charts/kubedbcom-elasticsearch-editor-options/ui/functions.js index 659cc5ccff..52e224192c 100644 --- a/charts/kubedbcom-elasticsearch-editor-options/ui/functions.js +++ b/charts/kubedbcom-elasticsearch-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,829 +317,845 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(modelPathValue) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Standalone', 'Replicaset'] + return validType.includes(modelPathValue) + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + if (val === 'capz' && ifDedicated()) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) - } -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] } else { - return resp.data?.status?.namespaces || [] + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] } - } catch (e) { - console.log(e) - } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Elasticsearch/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Elasticsearch/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Elasticsearch/mode/available') || [] - if (arr.length) defMode = arr[0] + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + return [] } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) - } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - setDiscriminatorValue('/bundleApiLoaded', true) -} + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!getValue(model, `/spec/admin/databases/Elasticsearch/mode/toggle`)) { + let defMode = getDefault('databases/Elasticsearch/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Elasticsearch/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + setDiscriminatorValue('/bundleApiLoaded', true) } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } + + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') + const options = getValue(model, `/spec/admin/${type}/available`) || [] + + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } + + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) + } + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } + + function onAuthChange() { commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/authSecret/name', + value: '', force: true, }) commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/authSecret/password', + value: '', force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} - -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} - -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} - -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled } -} -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} - -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - showAdditionalSettings, - returnFalse, - initBundle, - isVariantAvailable, - showAuthPasswordField, - isEqualToModelPathValue, - showStorageSizeField, - setMachineToCustom, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - getNamespaces, - isToggleOn, - getAdminOptions, - getNodeTopology, - filterNodeTopology, - getMachineListForOptions, - setLimits, - setRequests, - isMachineNotCustom, - isMachineCustom, - notEqualToDatabaseMode, - onAuthChange, - clearConfiguration, - isConfigDatabaseOn, - showIssuer, - setMonitoring, - updateAlertValue, - showAlerts, - onBackupSwitch, - setBackup, - getDefault, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + showAdditionalSettings, + returnFalse, + initBundle, + isVariantAvailable, + showAuthPasswordField, + isEqualToModelPathValue, + showStorageSizeField, + setMachineToCustom, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + getNamespaces, + isToggleOn, + getAdminOptions, + getNodeTopology, + filterNodeTopology, + getMachineListForOptions, + setLimits, + setRequests, + isMachineNotCustom, + isMachineCustom, + notEqualToDatabaseMode, + onAuthChange, + clearConfiguration, + isConfigDatabaseOn, + showIssuer, + setMonitoring, + updateAlertValue, + showAlerts, + onBackupSwitch, + setBackup, + getDefault, + } } diff --git a/charts/kubedbcom-elasticsearch-editor/ui/edit-ui.yaml b/charts/kubedbcom-elasticsearch-editor/ui/edit-ui.yaml index d21af611e2..60c0829e46 100644 --- a/charts/kubedbcom-elasticsearch-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-elasticsearch-editor/ui/edit-ui.yaml @@ -1,2349 +1,1052 @@ -steps: -- form: - discriminator: - createAuthSecret: - type: boolean - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - fetch: getResources|core|v1|namespaces - label: - text: labels.namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - disableUnselect: true - disabled: true - fetch: getElasticSearchVersions|catalog.kubedb.com|v1alpha1|elasticsearchversions - label: - text: labels.database.version - onChange: onVersionChange - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/version - type: select - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/deletionPolicy - type: radio - - disabled: true - label: - text: labels.disable_security_question - onChange: onDisableSecurityChange - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/disableSecurity - type: switch - - elements: - - label: - text: labels.database.admin_secret - type: label-element - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/authSecret/properties/name - type: input - if: isSecurityEnabled - type: single-step-form - type: single-step-form - id: basic - title: steps.0.label -- form: - elements: - - alias: reusable_alert - chart: - name: uibytebuildersdev-component-alert - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/form/properties/alert - type: reusable-element - type: single-step-form - id: alert - title: labels.alert -- form: - discriminator: - activeDatabaseMode: - type: string +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - label: - text: labels.to_update_disabled_section - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/elasticsearchopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations - - computed: setDatabaseMode - disabled: true - hasDescription: true - label: - text: labels.database.mode - onChange: deleteDatabaseModePath + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - description: options.database.mode.Combined.description - text: options.database.mode.Combined.label - value: Combined - - description: options.database.mode.Dedicated.description - text: options.database.mode.Dedicated.label - value: Dedicated - schema: - $ref: discriminator#/activeDatabaseMode - type: radio - - elements: - - disabled: true - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/replicas - type: input - - fetch: getMaxUnavailableOptions|/resources/kubedbComElasticsearch/spec - label: - text: labels.max_unavailable - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/maxUnavailable - type: select - - disabled: true - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/storage/properties/resources/properties/requests/properties/storage - type: input - - disabled: true - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/storage/properties/storageClassName - type: input - if: isEqualToDatabaseMode|Combined - type: single-step-form - - element: - elements: - - disabled: true - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/replicas - type: input - - fetch: getMaxUnavailableOptions - label: - text: labels.max_unavailable - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/maxUnavailable - type: select - - disabled: true - elements: - - elements: - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/storage/properties/resources/properties/requests/properties/storage - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/storage/properties/resources/properties/requests - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/storage/properties/resources - type: single-step-form - - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/storage/properties/storageClassName - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/storage - type: single-step-form - - disabled: true - label: - text: labels.suffix - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/suffix - type: input - - disabled: true - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn/properties/resources - type: resource-input-form - hideForm: true - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/$dyn - show_label: true - type: single-step-form - individualItemVisibilityCheck: hasTopologyNode - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology - type: array-input-form - type: single-step-form - id: topology - title: steps.1.label -- form: - discriminator: - internalUsers: - type: array - elements: - - addFormLabel: labels.user - computed: setInternalUsers - disabled: true - element: - discriminator: - users: - emitAs: internalUsers - type: array - elements: - - disabled: disableUsername - label: - text: labels.username - required: true - schema: - $ref: discriminator#/properties/users/items/properties/username - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.attributes - schema: - $ref: discriminator#/properties/users/items/properties/attributes - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: discriminator#/properties/users/items/properties/attributes/additionalProperties - type: input - - element: - label: - text: labels.role - schema: - $ref: discriminator#/properties/users/items/properties/backendRoles/items - type: input - label: - text: labels.backendRoles - schema: - $ref: discriminator#/properties/users/items/properties/backendRoles - type: list-input-form - - label: - text: labels.description - schema: - $ref: discriminator#/properties/users/items/properties/description - type: textarea - - label: - text: labels.hidden - schema: - $ref: discriminator#/properties/users/items/properties/hidden - type: switch - - element: - label: - text: labels.role - schema: - $ref: discriminator#/properties/users/items/properties/opendistroSecurityRoles/items - type: input - if: isAuthPluginEqualTo|OpenDistro - label: - text: labels.opendistro_security_roles - schema: - $ref: discriminator#/properties/users/items/properties/opendistroSecurityRoles - type: list-input-form - - label: - text: labels.reserved - schema: - $ref: discriminator#/properties/users/items/properties/reserved - type: switch - - element: - label: - text: labels.role - schema: - $ref: discriminator#/properties/users/items/properties/searchGuardRoles/items - type: input - if: isAuthPluginEqualTo|SearchGuard - label: - text: labels.search_guard_roles - schema: - $ref: discriminator#/properties/users/items/properties/searchGuardRoles - type: list-input-form - - allowUserDefinedOption: true - fetch: getSecrets - label: - text: labels.secret_name - schema: - $ref: discriminator#/properties/users/items/properties/secretName - type: select - type: single-step-form - individualItemDisabilityCheck: disableUserEdit - label: - text: labels.internal_users - newItemValidator: validateNewUser - onChange: onInternalUsersChange - schema: - $ref: discriminator#/properties/internalUsers - tableContents: - - inTableColumn: true - label: - text: labels.username - path: username - type: value - typeOfValue: string - - label: - text: labels.attributes - path: attributes - type: value - typeOfValue: key-value - - inTableColumn: true - label: - isSubsection: true - text: labels.backendRoles - path: backendRoles - type: value - typeOfValue: array - - label: - text: labels.description - path: description - type: value - typeOfValue: string - - label: - text: labels.hidden - path: hidden - type: value - typeOfValue: string - - label: - isSubsection: true - text: labels.opendistro_security_roles - path: opendistroSecurityRoles - type: value - typeOfValue: array - - inTableColumn: true - label: - text: labels.reserved - path: reserved - type: value - typeOfValue: string - - label: - isSubsection: true - text: labels.search_guard_roles - path: searchGuardRoles - type: value - typeOfValue: array - - inTableColumn: true - label: - text: labels.secret_name - path: secretName - type: value - typeOfValue: string - type: single-step-form-array - type: single-step-form - id: internal-users - if: showInternalUsersAndRolesMapping - title: steps.2.label -- form: - discriminator: - rolesMapping: - type: array - elements: - - addFormLabel: labels.role - computed: setRolesMapping - disabled: true - element: - discriminator: - roles: - emitAs: rolesMapping - type: array - elements: - - label: - text: labels.role_name - required: true - schema: - $ref: discriminator#/properties/roles/items/properties/roleName - type: input - - element: - label: - text: labels.role - schema: - $ref: discriminator#/properties/roles/items/properties/andBackendRoles/items - type: input - label: - text: labels.andBackendRoles - schema: - $ref: discriminator#/properties/roles/items/properties/andBackendRoles - type: list-input-form - - element: - label: - text: labels.role - schema: - $ref: discriminator#/properties/roles/items/properties/backendRoles/items - type: input - label: - text: labels.backendRoles - schema: - $ref: discriminator#/properties/roles/items/properties/backendRoles - type: list-input-form - - label: - text: labels.hidden - schema: - $ref: discriminator#/properties/roles/items/properties/hidden - type: switch - - element: - label: - text: labels.host - schema: - $ref: discriminator#/properties/roles/items/properties/hosts/items - type: input - label: - text: labels.hosts - schema: - $ref: discriminator#/properties/roles/items/properties/hosts - type: list-input-form - - label: - text: labels.reserved - schema: - $ref: discriminator#/properties/roles/items/properties/reserved - type: switch - - allowUserDefinedOption: true - fetch: getInternalUsers - label: - text: labels.users - schema: - $ref: discriminator#/properties/roles/items/properties/users - type: multiselect - type: single-step-form - label: - text: labels.roles_mapping - onChange: onRolesMappingChange - schema: - $ref: discriminator#/properties/rolesMapping - tableContents: - - inTableColumn: true - label: - text: labels.role_name - path: roleName - type: value - typeOfValue: string - - inTableColumn: true - label: - isSubsection: true - text: labels.backendRoles - path: backendRoles - type: value - typeOfValue: array - - inTableColumn: true - label: - text: labels.hidden - path: hidden - type: value - typeOfValue: string - - label: - isSubsection: true - text: labels.andBackendRoles - path: andBackendRoles - type: value - typeOfValue: array - - label: - isSubsection: true - text: labels.hosts - path: hosts - type: value - typeOfValue: array - - inTableColumn: true - label: - isSubsection: true - text: labels.users - path: users - type: value - typeOfValue: array - - label: - text: labels.reserved - path: reserved - type: value - typeOfValue: string - type: single-step-form-array - type: single-step-form - id: roles-mapping - if: showInternalUsersAndRolesMapping - title: steps.11.label -- form: - elements: - - discriminator: - customizeKernelSettings: - type: string + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - computed: returnStringYes - label: - text: labels.customizeKernelSettings - onChange: onCustomizeKernelSettingChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.kernelSettings.no - value: "no" - - text: options.kernelSettings.disable - value: disable - schema: - $ref: discriminator#/properties/customizeKernelSettings - type: radio - - if: isDiscriminatorEqualTo|/customizeKernelSettings|yes - label: - text: labels.privileged_question - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/kernelSettings/properties/privileged - type: switch - - addFormLabel: labels.sysctl - element: - elements: - - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/kernelSettings/properties/sysctls/items/properties/name - type: input - - label: - text: labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/kernelSettings/properties/sysctls/items/properties/value - type: input - type: single-step-form - if: isDiscriminatorEqualTo|/customizeKernelSettings|yes - label: - text: labels.sysctls - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/kernelSettings/properties/sysctls - tableContents: - - inTableColumn: true - label: - text: labels.name - path: name - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.value - path: value - type: value - typeOfValue: string - type: single-step-form-array - keepEmpty: true - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/kernelSettings - type: single-step-form - type: single-step-form - id: kernel-settings - title: steps.10.label -- form: - discriminator: - configureTLS: - default: true - type: boolean - elements: - - if: showTlsRecommendation - label: - text: labels.tls_recommended_text - type: label-element - - label: - text: labels.to_update_tls - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/elasticsearchopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=ReconfigureTLS - - computed: isValueExistInModel|/resources/kubedbComMariaDB/spec/tls - disabled: true - label: - text: labels.enable_tls - onChange: onTlsConfigureChange - schema: - $ref: discriminator#/configureTLS - type: switch - - disabled: true - elements: - - label: - text: labels.enable_ssl_question - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/enableSSL - type: switch - - elements: - - computed: setApiGroupEdit - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: returnFalse - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - required: returnFalse - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - if: isSecurityEnabled - title: steps.3.label -- form: - elements: - - disabled: disableInitializationSection - discriminator: - prePopulateDatabase: - type: string - elements: - - computed: initPrePopulateDatabase - label: - text: labels.prePopulateDatabase - onChange: onPrePopulateDatabaseChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/prePopulateDatabase - type: radio - - discriminator: - dataSource: - type: string - elements: - - computed: initDataSource - label: - text: labels.dataSource - onChange: onDataSourceChange + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true options: - - text: options.dataSource.script.text - value: script - - text: options.dataSource.stashBackup.text - value: stashBackup - schema: - $ref: discriminator#/properties/dataSource - type: select - - discriminator: - sourceVolumeType: - type: string + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig elements: - - label: - text: labels.script.path - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/init/properties/script/properties/scriptPath - type: input - - label: - text: labels.script.volume - type: label-element - - computed: initVolumeType - label: - text: labels.script.volumeType - onChange: onVolumeTypeChange - options: - - text: options.scriptSourceVolumeType.configMap.text - value: configMap - - text: options.scriptSourceVolumeType.secret.text - value: secret - schema: - $ref: discriminator#/properties/sourceVolumeType - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|configmaps - if: showConfigMapOrSecretName|configMap - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/init/properties/script/properties/configMap/properties/name - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|secrets - if: showConfigMapOrSecretName|secret - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/init/properties/script/properties/secret/properties/secretName - type: select - if: showScriptOrStashForm|script - type: single-step-form - - elements: - - label: - text: labels.restoreSession.snapshot - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/rules/properties/0/properties/snapshots/properties/0 - type: input - - discriminator: - repositoryChoise: - type: string - elements: - - label: - text: labels.repositories.title - type: label-element - - computed: setInitialRestoreSessionRepo - onChange: onInitRepositoryChoiseChange - options: - - text: options.createOrSelect.select.text - value: select - - text: options.createOrSelect.create.text - value: create - schema: - $ref: discriminator#/properties/repositoryChoise - type: radio - - allowUserDefinedOption: true - fetch: resourceNames|stash.appscode.com|v1alpha1|repositories - if: showRepositorySelectOrCreate|select - label: - text: labels.repositories.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/repository/properties/name - type: select - - alias: repository_create_init - chart: - name: uibytebuildersdev-component-repository-create - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRepositorySelectOrCreate|create - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRepository_init_repo/properties/spec/properties/backend - type: reusable-element - type: single-step-form - - if: returnFalse - label: - text: labels.backupConfiguration.targetReference.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/target/properties/ref/properties/name - type: input - - discriminator: - customizeRestoreJobRuntimeSettings: - type: string - elements: - - computed: initCustomizeRestoreJobRuntimeSettings - label: - isSubsection: true - text: labels.runtimeSettings.choise - onChange: onCustomizeRestoreJobRuntimeSettingsChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/customizeRestoreJobRuntimeSettings - type: radio - - alias: runtime_settings_init - chart: - name: uibytebuildersdev-component-runtime-settings - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRuntimeForm|yes - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/runtimeSettings - type: reusable-element - type: single-step-form - if: showScriptOrStashForm|stashBackup - type: single-step-form - - if: returnFalse - label: - text: labels.waitForInitialRestore - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/init/properties/waitForInitialRestore - type: switch - if: showInitializationForm - type: single-step-form - type: single-step-form - type: single-step-form - id: initialization - title: steps.4.label -- form: - discriminator: - repoInitialSelectionStatus: - type: string - scheduleBackup: - default: "yes" - type: string + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - computed: initScheduleBackupForEdit - if: showScheduleBackup - label: - text: labels.backup.title - onChange: onScheduleBackupChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/scheduleBackup - type: radio - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean - elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string - elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean + - type: block-layout + if: + type: function + name: isConsole elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean - elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - if: showBackupForm - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.5.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComElasticsearch/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComElasticsearch/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComElasticsearch/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComElasticsearch/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.6.label -- form: - elements: - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - topology: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - id: pod-template - title: steps.7.label -- form: - elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.8.label -- form: - elements: - - discriminator: - setCustomConfig: - type: string - elements: - - computed: initSetCustomConfig - label: - text: labels.setCustomConfig - onChange: onSetCustomConfigChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/setCustomConfig - type: radio - - discriminator: - configFiles: - type: string - configurationSource: - default: use-existing-config - type: string + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - computed: setConfigurationSource - label: - text: labels.custom_config_type - onChange: onConfigurationSourceChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/configurationSource - type: radio - - allowUserDefinedOption: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSource - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/configSecret/properties/name - type: select - - addFormLabel: labels.config_file - computed: setConfigFiles - element: - discriminator: - files: - emitAs: configFiles - type: array + # Node mode + - type: block-layout + label: Node + showLabels: true + if: + type: function + name: dbTypeEqualsTo|node + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node elements: - - label: - text: labels.filename - required: true - schema: - $ref: discriminator#/properties/files/items/properties/key - type: input - - label: - text: labels.labels.value - required: true - schema: - $ref: discriminator#/properties/files/items/properties/value - type: editor - type: single-step-form - if: isEqualToDiscriminatorPath|create-new-config|/configurationSource - label: - text: labels.config_files - onChange: onConfigFilesChange - schema: - $ref: discriminator#/properties/configFiles - tableContents: - - inTableColumn: true - label: - text: labels.filename - path: key - type: value - typeOfValue: string - - label: - text: labels.labels.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - if: isDiscriminatorEqualTo|/setCustomConfig|yes - type: single-step-form - type: single-step-form - type: single-step-form - id: custom-config - title: steps.9.label -- form: - elements: - - discriminator: - setSecretCustomConfig: - type: string - elements: - - computed: initSetSecureCustomConfig - label: - text: labels.setSecretCustomConfig - onChange: onSetSecretCustomConfigChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/setSecretCustomConfig - type: radio - - discriminator: - configFiles: - type: string - configurationSource: - default: use-existing-config - type: string - elements: - - computed: setSecretConfigurationSource - label: - text: labels.secret_custom_config_type - onChange: onSecretConfigurationSourceChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/configurationSource - type: radio - - allowUserDefinedOption: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSource - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/secureConfigSecret/properties/name - type: select - - addFormLabel: labels.config_file - computed: setSecretConfigFiles - element: - discriminator: - files: - emitAs: configFiles - type: array + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/compute/node/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|node + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|node + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|node + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/inMemoryStorage + elements: + - type: threshold-input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: threshold-input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/inMemoryStorage/properties/usageThresholdPercentage + + # Topology mode - Data + - type: block-layout + label: Data + showLabels: true + if: + type: function + name: dbTypeEqualsTo|topology + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data elements: - - label: - text: labels.settings_key - required: true - schema: - $ref: discriminator#/properties/files/items/properties/key - type: input - - label: - text: labels.settings_value - required: true - schema: - $ref: discriminator#/properties/files/items/properties/value - type: editor - type: single-step-form - if: isEqualToDiscriminatorPath|create-new-config|/configurationSource - label: - text: labels.config_files - onChange: onSecretConfigFilesChange - schema: - $ref: discriminator#/properties/configFiles - tableContents: - - inTableColumn: true - label: - text: labels.settings_key - path: key - type: value - typeOfValue: string - - label: - text: labels.settings_value - path: value - type: value - typeOfValue: code - type: single-step-form-array - if: isDiscriminatorEqualTo|/setSecretCustomConfig|yes - type: single-step-form - type: single-step-form - type: single-step-form - id: secure-custom-config - if: showSecureCustomConfig - title: steps.12.label -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: SelectDb - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: SelectType - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array - elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/compute/node/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-node-max: - type: string - allowedMachine-node-min: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/compute/data/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|data + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|data + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|data + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/inMemoryStorage + elements: + - type: threshold-input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: threshold-input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/inMemoryStorage/properties/usageThresholdPercentage + + # Topology mode - Ingest + - type: block-layout + label: Ingest + showLabels: true + if: + type: function + name: dbTypeEqualsTo|topology + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest elements: - - computed: setAllowedMachine|node|min - disableUnselect: true - fetch: getMachines|node|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|node - schema: - $ref: discriminator#/properties/allowedMachine-node-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|node|max - disableUnselect: true - fetch: getMachines|node|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|node - schema: - $ref: discriminator#/properties/allowedMachine-node-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|node - label: - text: controlledResources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node/properties/controlledResources - type: multiselect - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node - type: single-step-form - if: dbTypeEqualsTo|node - label: - text: Node - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node - show_label: true - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/compute/data/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-data-max: - type: string - allowedMachine-data-min: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/compute/ingest/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|ingest + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|ingest + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|ingest + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/inMemoryStorage + elements: + - type: threshold-input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: threshold-input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/inMemoryStorage/properties/usageThresholdPercentage + + # Topology mode - Master + - type: block-layout + label: Master + showLabels: true + if: + type: function + name: dbTypeEqualsTo|topology + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master elements: - - computed: setAllowedMachine|data|min - disableUnselect: true - fetch: getMachines|data|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|data - schema: - $ref: discriminator#/properties/allowedMachine-data-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|data|max - disableUnselect: true - fetch: getMachines|data|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|data - schema: - $ref: discriminator#/properties/allowedMachine-data-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|data - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data/properties/controlledResources - type: multiselect - label: - text: Data - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/data - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/compute/ingest/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/podLifeTimeThreshold - type: input - - label: - text: ResourceDiffPercentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-ingest-max: - type: string - allowedMachine-ingest-min: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/compute/master/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|master + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|master + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|master + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/inMemoryStorage + elements: + - type: threshold-input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: threshold-input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/inMemoryStorage/properties/usageThresholdPercentage + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/nodeTopology elements: - - computed: setAllowedMachine|ingest|min - disableUnselect: true - fetch: getMachines|ingest|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|ingest - schema: - $ref: discriminator#/properties/allowedMachine-ingest-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|ingest|max - disableUnselect: true - fetch: getMachines|ingest|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|ingest - schema: - $ref: discriminator#/properties/allowedMachine-ingest-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|ingest - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest/properties/controlledResources - type: multiselect - label: - text: Ingest - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/ingest - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/compute/master/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-master-max: - type: string - allowedMachine-master-min: - type: string + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions elements: - - computed: setAllowedMachine|master|min - disableUnselect: true - fetch: getMachines|master|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|master - schema: - $ref: discriminator#/properties/allowedMachine-master-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|master|max - disableUnselect: true - fetch: getMachines|master|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|master - schema: - $ref: discriminator#/properties/allowedMachine-master-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|master - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master/properties/controlledResources - type: multiselect - label: - text: Master - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/master - show_label: true - type: single-step-form - if: dbTypeEqualsTo|topology - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: nodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: OpsRequest Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.13.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: SelectDb - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: SelectType - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/node/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/trigger - type: select - - label: - text: Expansion Mode + - type: block-layout + showLabels: false + elements: + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: Node + showLabels: true + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/node/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComElasticsearch/spec/topology/data/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/node/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules + # elements: + # - type: input + # label: AppliesUpto (In Storage units) + # schema: appliesUpto + # - type: input + # label: Threshold (In %, Or In Storage Units) + # schema: threshold + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/node/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring + elements: + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComElasticsearch/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection + elements: + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComElasticsearch/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComElasticsearch/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/node/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/node/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound - type: input - if: dbTypeEqualsTo|node - label: - text: Node - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/compute/properties/node - show_label: true - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/data/trigger - label: - text: trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/data/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/data/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/data/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/data/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/data/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/data/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/data/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/data/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/data/properties/upperBound - type: input - label: - text: Data - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/data - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/ingest/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/ingest/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/ingest/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/ingest/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/ingest/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/ingest/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/ingest/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/ingest/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/ingest/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/ingest/properties/upperBound - type: input - label: - text: Ingest - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/ingest - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/master/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/master/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/master/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/master/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/master/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/master/properties/scalingRules/items/properties/threshold + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComElasticsearch/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/master/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/master/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComElasticsearchAutoscaler/spec/storage/master/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/master/properties/upperBound - type: input - label: - text: Master - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/storage/properties/master - show_label: true - type: single-step-form - if: dbTypeEqualsTo|topology - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: OpsRequest Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComElasticsearchAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.0.label -- form: - discriminator: - binding: - default: false - type: boolean + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: binding + label: Gateway Binding elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -type: multi-step-form + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-elasticsearch-editor/ui/functions.js b/charts/kubedbcom-elasticsearch-editor/ui/functions.js index 06318c21bc..bc725bd90d 100644 --- a/charts/kubedbcom-elasticsearch-editor/ui/functions.js +++ b/charts/kubedbcom-elasticsearch-editor/ui/functions.js @@ -1,3573 +1,1489 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx, setDiscriminatorValue }, discriminatorPath) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - if (discriminatorPath) { - setDiscriminatorValue(discriminatorPath, { - ui: ui.data || {}, - language: language.data || {}, - functions, - }) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + /********** Initialize Discriminator **************/ -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') - const resources = (resp && resp.data && resp.data.items) || [] + // Compute Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + const stashAppscodeComBackupConfiguration = { + spec: { + repository: { + name: '', + }, + retentionPolicy: { + keepLast: 5, + name: 'keep-last-5', + prune: true, + }, + schedule: '*/5 * * * *', + target: { + ref: { + apiVersion: 'appcatalog.appscode.com/v1alpha1', + kind: 'AppBinding', + name: '', + }, + }, + }, } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + initRepositoryChoiseForEdit() - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + function initScheduleBackup() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } - return ans -} + function onScheduleBackupChange() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (scheduleBackup === 'no') { + // delete stashAppscodeComBackupConfiguration + commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + // delete annotation from kubedbComElasticsearch annotation + deleteKubeDbComElasticsearchDbAnnotation(getValue, model, commit) + } else { + const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + // create stashAppscodeComBackupConfiguration and initialize it if not exists - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const dbName = getValue(model, '/metadata/release/name') - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + if ( + !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && + !isBluePrint + ) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration', + value: stashAppscodeComBackupConfiguration, + }) + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + } + } } - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + function deleteKubedbComElasticsearchDbAnnotation(getValue, model, commit) { + const annotations = + getValue(model, '/resources/kubedbComElasticsearch/metadata/annotations') || {} + const filteredKeyList = + Object.keys(annotations).filter( + (k) => + k !== 'stash.appscode.com/backup-blueprint' && + k !== 'stash.appscode.com/schedule' && + !k.startsWith('params.stash.appscode.com/'), + ) || [] + const filteredAnnotations = {} + filteredKeyList.forEach((k) => { + filteredAnnotations[k] = annotations[k] + }) + commit('wizard/model$update', { + path: '/resources/kubedbComElasticsearch/metadata/annotations', + value: filteredAnnotations, }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' + function getBackupConfigsAndAnnotations(getValue, model) { + const stashAppscodeComBackupConfiguration = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration', + ) + const kubedbComElasticsearchAnnotations = + getValue(model, '/resources/kubedbComElasticsearch/metadata/annotations') || {} + + const isBluePrint = Object.keys(kubedbComElasticsearchAnnotations).some( + (k) => + k === 'stash.appscode.com/backup-blueprint' || + k === 'stash.appscode.com/schedule' || + k.startsWith('params.stash.appscode.com/'), + ) + return { - text: name, - value: name, + stashAppscodeComBackupConfiguration, + isBluePrint, } - }) -} + } -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + // backup form + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false + } + + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let namespaceList = [] + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComElasticsearch') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined + + // get values.yaml to populate data when backup-config is being created + try { + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version + + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` + + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` + + const resp = await axios.get(url) + + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} + } catch (e) { + console.log(e) } - }) -} -function returnTrue() { - return true -} + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } + } -function returnStringYes() { - return 'yes' -} + // check config with metadata name first + let config = configs?.find( + (item) => + item.metadata?.name === name && + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) -function isDedicatedModeSelected({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/topology') - isDedicatedSelected = getValue(model, '/resources/kubedbComElasticsearch/spec/topology') + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - return !!isDedicatedSelected -} + // set backup switch here + isBackupOn = !!config -function isCombinedModeSelected({ model, getValue, watchDependency }) { - return !isDedicatedSelected({ model, getValue, watchDependency }) -} + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset -function isDiscriminatorEqualTo( - { discriminator, getValue, watchDependency }, - discriminatorPath, - value, -) { - watchDependency('discriminator#' + discriminatorPath) - const pathValue = getValue(discriminator, discriminatorPath) + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends - return value === pathValue -} + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` -function isAuthPluginNotSearchGuard({ discriminator, getValue, watchDependency, commit }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') - const pathValue = getValue(discriminator, '/selectedVersionAuthPlugin') + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions + } - if (!pathValue) return false + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } - const ret = pathValue !== 'SearchGuard' && pathValue !== '' + setDiscriminatorValue('isBackupDataLoaded', true) + } - if (!ret) { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/dataWarm') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/dataHot') + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') } - return ret -} -// required for outer form section. where discriminator can not be saved -async function showInternalUsersAndRolesMapping({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - commit, -}) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/disableSecurity') - watchDependency('model#/resources/kubedbComElasticsearch/spec/version') - - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) + function setBackupType() { + return 'BackupConfig' + } - const ret = - (dist === 'OpenDistro' || dist === 'SearchGuard') && - isSecurityEnabled({ model, getValue, watchDependency }) + function getTypes() { + const arr = [ + { + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', + }, + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] - if (ret) { - commit('wizard/showSteps$update', { - stepId: 'internal-users', - show: true, - }) + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) + } + return arr + } - commit('wizard/showSteps$update', { - stepId: 'roles-mapping', - show: true, - }) - } else { - commit('wizard/showSteps$update', { - stepId: 'internal-users', - show: false, + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') + commit('wizard/model$update', { + path: '/backupType', + value: type, + force: true, }) - - commit('wizard/showSteps$update', { - stepId: 'roles-mapping', - show: false, + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), + force: true, + }) + } + commit('wizard/model$delete', '/context') + commit('wizard/model$update', { + path: '/resources/kubedbComElasticsearch', + value: objectCopy(dbResource), + force: true, }) } - return ret -} -// required for outer form section. where discriminator can not be saved -async function showSecureCustomConfig({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - commit, -}) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/version') - - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') - const ret = dist === 'X-Pack' + return selectedType === type + } - if (ret) { - commit('wizard/showSteps$update', { - stepId: 'secure-custom-config', - show: true, - }) - } else { - commit('wizard/showSteps$update', { - stepId: 'secure-custom-config', - show: false, - }) + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/secureConfigSecret') - commit('wizard/model$delete', '/resources/secret_secure_config') + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) } - return ret -} -// ************************* Basic Info ********************************************** + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') -async function getElasticSearchVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (blueprintSwitch) addLabelAnnotation('annotations') + else deleteLabelAnnotation('annotations') + } - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, authPlugin: null }, - }, - }, + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComElasticsearch/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) + } else { + commit('wizard/model$delete', path) + } + } - const resources = (resp && resp.data && resp.data.items) || [] + function addLabelAnnotation(type) { + const obj = objectCopy(initialDbMetadata[type]) - // keep only non deprecated versions - const filteredElasticSearchVersions = resources.filter( - (item) => item.spec && !item.spec.deprecated, - ) + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` + } else { + obj['kubedb.com/archiver'] = 'true' + } - filteredElasticSearchVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredElasticSearchVersions -} + commit('wizard/model$update', { + path: `/resources/kubedbComElasticsearch/metadata/${type}`, + value: obj, + force: true, + }) + } -function isSecurityEnabled({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/disableSecurity') - const value = getValue(model, '/resources/kubedbComElasticsearch/spec/disableSecurity') - return !value -} + function deleteLabelAnnotation(type) { + const obj = initialDbMetadata[type] -function onDisableSecurityChange({ model, getValue, commit }) { - const disableSecurity = getValue(model, '/resources/kubedbComElasticsearch/spec/disableSecurity') + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] - if (disableSecurity) { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/authSecret') - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/internalUsers') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/rolesMapping') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/tls') + commit('wizard/model$update', { + path: `/resources/kubedbComElasticsearch/metadata/${type}`, + value: obj, + force: true, + }) } -} -async function onVersionChange({ - model, - getValue, - watchDependency, - axios, - storeGet, - commit, - setDiscriminatorValue, -}) { - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - - const isOpenDistro = dist === 'OpenDistro' - const isSearchGuard = dist === 'SearchGuard' - const isXpack = dist === 'X-Pack' - - if (!isOpenDistro && !isSearchGuard) { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/internalUsers') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/rolesMapping') - if (isXpack) { - removeCertificatesOfAliases({ model, getValue, commit }, ['admin']) - } - } else { - if (!isOpenDistro) { - const internalUsers = getValue(model, '/resources/kubedbComElasticsearch/spec/internalUsers') - - if (internalUsers) { - Object.keys(internalUsers).map((key) => { - if (internalUsers[key]?.opendistroSecurityRoles) - delete internalUsers[key]?.opendistroSecurityRoles - }) - } + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') + commit('wizard/model$update', { + path: '/context', + value: context, + force: true, + }) + if (context === 'Create') { commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/internalUsers', - value: internalUsers, + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, force: true, }) - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/dataHot') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/dataWarm') } - if (!isSearchGuard) { - const internalUsers = getValue(model, '/resources/kubedbComElasticsearch/spec/internalUsers') + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) + } - if (internalUsers) { - Object.keys(internalUsers).map((key) => { - if (internalUsers[key]?.searchGuardRoles) delete internalUsers[key]?.searchGuardRoles - }) - } + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) + const list = filteredList?.map((ele) => ele.metadata.name) + return list + } - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/internalUsers', - value: internalUsers, - force: true, - }) - } + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) - if (!isXpack) { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/dataCold') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/dataContent') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/dataFrozen') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/ml') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology/transform') - } + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: configDetails, + force: true, + }) } -} -function onEnableSSLChange({ model, getValue, commit }) { - const enabelSSL = getValue(model, '/resources/kubedbComElasticsearch/spec/enableSSL') + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' + } - if (enabelSSL === false) { - removeCertificatesOfAliases({ model, getValue, commit }, [ - 'http', - 'archiver', - 'metrics-exporter', - ]) + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' } -} -function removeCertificatesOfAliases({ model, getValue, commit }, aliasesToRemove) { - const certificates = - getValue(model, '/resources/kubedbComElasticsearch/spec/tls/certificates') || [] - const updatedCertificates = certificates.filter((item) => !aliasesToRemove.includes(item.alias)) - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/tls/certificates', - value: updatedCertificates, - force: true, - }) -} + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName + } -/************************************* Database Secret Section ********************************************/ + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComElasticsearch/spec/authSecret') + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' + } - return !authSecret -} + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') + return repoInitialSelectionStatus + } - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value + commit('wizard/model$update', { + path: modelPath, + value: session, + }) + } + } -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} + // binding -function setAuthSecretPassword({ model, getValue, watchDependency, discriminator, commit }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComElasticsearch/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'ElasticsearchBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } - const dist = getValue(discriminator, '/selectedVersionAuthPlugin') - if (dist) { - if (dist === 'X-Pack') { - const encodedPassword = getValue(model, '/resources/secret_elastic_cred/data/password') - commit('wizard/model$delete', '/resources/secret_admin_cred') - return encodedPassword ? decodePassword({}, encodedPassword) : '' + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComElasticsearchBinding', + value: bindingValues, + force: true, + }) } else { - const encodedPassword = getValue(model, '/resources/secret_admin_cred/data/password') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - return encodedPassword ? decodePassword({}, encodedPassword) : '' + commit('wizard/model$delete', '/resources/catalogAppscodeComElasticsearchBinding') } } -} -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - const dist = getValue(discriminator, '/selectedVersionAuthPlugin') + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComElasticsearchBinding') + return isExposeBinding + } - if (dist) { - if (stringPassword) { - if (dist === 'X-Pack') { - commit('wizard/model$update', { - path: '/resources/secret_elastic_cred/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_elastic_cred/data/username', - value: encodePassword({}, 'elastic'), - force: true, - }) - commit('wizard/model$delete', '/resources/secret_admin_cred') - } else { + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } + + // storage + + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { commit('wizard/model$update', { - path: '/resources/secret_admin_cred/data/password', - value: encodePassword({}, stringPassword), + path: `/resources/${path}`, + value: updatedValue, force: true, }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' commit('wizard/model$update', { - path: '/resources/secret_admin_cred/data/username', - value: encodePassword({}, 'admin'), + path: `/resources/${path}`, + value: value, force: true, }) - commit('wizard/model$delete', '/resources/secret_elastic_cred') } - } else { - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') } } -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + // compute - const secrets = (resp && resp.data && resp.data.items) || [] + let autoscaleType = '' + let dbDetails = {} - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' + const name = + storeGet('/route/params/name') || + getValue( + model, + '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', + ) || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/elasticsearches/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingkubedbComElasticsearchAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingkubedbComElasticsearchAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] } -} -function showSecretSection({ model, getValue, watchDependency, storeGet }) { - const steps = storeGet('/wizard/configureOptions') + function isConsole() { + const isKube = isKubedb() - return ( - !steps.includes('internal-users') && isSecurityEnabled({ model, getValue, watchDependency }) - ) -} - -// ********************* Database Mode *********************** -function isNotCombinedMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Combined' -} + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: namespace, + force: true, + }) + } + } -function setDatabaseMode({ model, getValue }) { - isDedicatedSelected = getValue(model, '/resources/kubedbComElasticsearch/spec/topology') - if (isDedicatedSelected) { - return 'Dedicated' - } else { - return 'Combined' + return !isKube } -} -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, setDiscriminatorValue, getValue, model }, - path, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resources = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) + const resources = (resp && resp.data && resp.data.items) || [] - if (!path) { - setDiscriminatorValue('/storageClasses', resources) + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - storageClassList = resources - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ model, getValue, commit }, path) - return resources -} - -function setStorageClass({ model, getValue, commit }, path) { - const deletionPolicy = - getValue(model, 'resources/kubedbComElasticsearch/spec/deletionPolicy') || '' - let storageClass = getValue(model, path) || '' - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) - - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + function onNamespaceChange() { + const namespace = getValue(model, '/metadata/namespace') + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', + ) } } - if (storageClass && path) { - commit('wizard/model$update', { - path: path, - value: storageClass, - force: true, - }) - } -} + function initMetadata() { + const dbName = + getValue( + model, + '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', + ) || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) + commit('wizard/model$update', { + path: '/metadata/name', + value: modifiedName, + force: true, + }) -function deleteDatabaseModePath({ discriminator, getValue, commit }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - if (mode === 'Dedicated') { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/maxUnavailable') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/podTemplate') - } else if (mode === 'Combined') { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/topology') + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute', + ) } -} -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') + async function fetchTopologyMachines() { + const instance = hasAnnotations() - return mode === value -} + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) -function getMaxUnavailableOptions({ model, getValue, watchDependency, commit, elementUi }, path) { - let prefixPath - if (path) { - prefixPath = path - } else { - const { $ref } = elementUi.schema || {} - const replacedPath = ($ref || '').replace( - 'schema#/properties/resources/properties/kubedbComElasticsearch/properties/spec/properties/topology/properties/', - '', - ) - const dyn = replacedPath.split('/').shift() - prefixPath = `/resources/kubedbComElasticsearch/spec/topology/${dyn}` + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } - watchDependency(`model#${prefixPath}/replicas`) + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } - const replicas = getValue(model, `${prefixPath}/replicas`) - const maxUnavailable = getValue(model, `${prefixPath}/maxUnavailable`) + function hasAnnotations(type) { + const annotations = + getValue( + model, + '/resources/autoscalingKubedbComElasticsearchAutoscaler/metadata/annotations', + ) || {} + const instance = annotations['kubernetes.io/instance-type'] - if (maxUnavailable > replicas) { - commit('wizard/model$update', { - path: `${prefixPath}/maxUnavailable`, - value: replicas, - force: true, - }) + return !!instance } - const options = [] + function setAllowedMachine(type, minmax) { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComElasticsearchAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } - for (let i = 0; i <= Math.min(replicas, 1000); i++) { - options.push(i) + const machine = parsedInstance[type] || '' + const mx = machine?.includes(',') ? machine.split(',')[1] : '' + const mn = machine?.includes(',') ? machine.split(',')[0] : '' + + if (minmax === 'min') return mn + else return mx } - return options -} -function getStorageClassNamesFromDiscriminator( - { model, discriminator, getValue, watchDependency, commit }, - path, -) { - watchDependency('discriminator#/storageClasses') - const options = getValue(discriminator, '/storageClasses') || [] + async function getMachines(type, minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${type}-${depends}` - setStorageClass({ model, getValue, commit }, path) + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - return options -} + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] -async function getSelectedVersionAuthPlugin( - { model, getValue, watchDependency, axios, storeGet, setDiscriminatorValue }, - path, -) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/version') - const version = getValue(model, '/resources/kubedbComElasticsearch/spec/version') || '' - - const elasticVersions = await getElasticSearchVersions( - { axios, storeGet }, - 'catalog.kubedb.com', - 'v1alpha1', - 'elasticsearchversions', - ) + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - const selectedVersion = elasticVersions?.find((item) => item.value === version) + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) - const ret = selectedVersion?.spec?.authPlugin || '' + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - if (path) { - setDiscriminatorValue(path, ret) + return dependantIndex === -1 ? machines : filteredMachine } - return ret -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComElasticsearchAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } -function onNodeSwitchFalse({ elementSchema, commit }) { - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - commit('wizard/model$delete', `/resources/kubedbComElasticsearch/spec/topology/${node}`) -} + const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) + const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) + const minMaxMachine = `${minMachine},${maxMachine}` -function hasTopologyNode({ model, getValue, itemCtx }) { - const nodeValue = getValue(model, `/resources/kubedbComElasticsearch/spec/topology/${itemCtx}`) + parsedInstance[type] = minMaxMachine + const instanceString = JSON.stringify(parsedInstance) + annotations['kubernetes.io/instance-type'] = instanceString - return !nodeValue -} + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute/${type}` -function hideNode({ itemCtx, discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') - const authPlugin = getValue(discriminator, '/selectedVersionAuthPlugin') - - let hiddenNodes = ['coordinating'] - - if (authPlugin === 'OpenDistro') { - hiddenNodes = ['coordinating', 'ml', 'dataCold', 'dataFrozen', 'dataContent', 'transform'] - } else if (authPlugin === 'SearchGuard') { - hiddenNodes = [ - 'coordinating', - 'ml', - 'dataWarm', - 'dataHot', - 'dataCold', - 'dataFrozen', - 'dataContent', - 'transform', - ] + if (minMachine && maxMachine && instance !== instanceString) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: annotations, + force: true, + }) + } } - const verd = hiddenNodes.includes(itemCtx) - return verd -} - -function setInitialStatusFalse({ elementSchema }) { - const disableNodes = ['master', 'data', 'ingest'] - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - return !disableNodes.includes(node) -} - -function disableNode({ elementSchema }) { - const disableNodes = ['master', 'data', 'ingest'] - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - return disableNodes.includes(node) -} - -// ************************** Internal Users ******************************** - -const defaultUsers = [ - 'admin', - 'kibanaro', - 'kibanaserver', - 'logstash', - 'readall', - 'snapshotrestore', - 'metrics_exporter', -] - -function onInternalUsersChange({ discriminator, getValue, commit }) { - const users = getValue(discriminator, '/internalUsers') - - const internalUsers = {} - - if (users) { - users.forEach((item) => { - const { username, createCred, secretName, password, ...obj } = item - if (createCred === 'no') { - obj.secretName = secretName - commit('wizard/model$delete', `/resources/secret_${username}_cred`) - } else if (createCred === 'yes') { - if (password) { - commit('wizard/model$update', { - path: `/resources/secret_${username}_cred/data/password`, - value: encodePassword({}, password), - force: true, - }) - commit('wizard/model$update', { - path: `/resources/secret_${username}_cred/data/username`, - value: encodePassword({}, username), - force: true, - }) - } else { - commit('wizard/model$delete', `/resources/secret_${username}_cred`) - } - } - internalUsers[username] = obj - }) + function hasNoAnnotations() { + return !hasAnnotations() } - if (Object.keys(internalUsers).length) { + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute/${type}/controlledResources` commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/internalUsers', - value: internalUsers, + path: path, + value: list, force: true, }) - } else { - // on initial call discriminator value is undefined - // to ignore model$delete for this case, - // users value checking is required, - // model$delete will be executed only if users value is not falsy value (empty array) - // and internalUsers is emptyObject - if (users) commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/internalUsers') + return list } -} - -function setInternalUsers({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/internalUsers') - const internalUsers = getValue(model, '/resources/kubedbComElasticsearch/spec/internalUsers') - const users = [] + function dbTypeEqualsTo(type) { + // watchDependency('discriminator#/dbDetails') - for (const item in internalUsers) { - internalUsers[item].username = item - const encodedPassword = getValue(model, `/resources/secret_${item}_cred/data/password`) - if (internalUsers[item].secretName) { - internalUsers[item].createCred = 'no' - } else { - if (encodedPassword) { - internalUsers[item].password = decodePassword({}, encodedPassword) - } - internalUsers[item].createCred = 'yes' - } - users.push(internalUsers[item]) + const { spec } = dbDetails || {} + const { topology } = spec || {} + let verd = '' + if (topology) verd = 'topology' + else verd = 'node' + clearSpecModel(verd) + return type === verd && spec } - setDiscriminatorValue('/internalUsers', users) - - return users -} - -function validateNewUser({ itemCtx }) { - if (defaultUsers.includes(itemCtx.username) && itemCtx.isCreate) { - return { isInvalid: true, message: "Can't use this username" } + function clearSpecModel(dbtype) { + if (dbtype === 'node') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/${autoscaleType}/data`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/${autoscaleType}/ingest`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/${autoscaleType}/master`, + ) + } else if (dbtype === 'topology') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/${autoscaleType}/node`, + ) + } } - return {} -} - -function disableUsername({ rootModel }) { - return defaultUsers.includes(rootModel && rootModel.username) -} -function disableUserEdit({ itemCtx }) { - if (defaultUsers.includes(itemCtx.username)) { - return { isEditDisabled: false, isDeleteDisabled: true } + // monitoring + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value } - return {} -} - -async function isAuthPluginEqualTo( - { model, getValue, watchDependency, axios, storeGet, setDiscriminatorValue }, - authPlugin, -) { - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - return dist === authPlugin -} - -// internal user cred -function showPasswordCredSection({ rootModel, getValue, watchDependency }) { - watchDependency('rootModel#/createCred') - const createCred = getValue(rootModel, '/createCred') - - return createCred === 'yes' -} - -function showExistingCredSection({ rootModel, getValue, watchDependency }) { - return !showPasswordCredSection({ rootModel, getValue, watchDependency }) -} - -function disableRoleDeletion({ itemCtx, rootModel }) { - return itemCtx === 'admin' && rootModel.username === 'admin' -} - -// ************************** Roles Mapping ******************************** -const defaultRoles = ['readall_and_monitor'] + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function onRolesMappingChange({ discriminator, getValue, commit }) { - const roles = getValue(discriminator, '/rolesMapping') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const rolesMapping = {} + const resources = (resp && resp.data && resp.data.items) || [] - if (roles) { - roles.forEach((item) => { - const { roleName, ...obj } = item - rolesMapping[roleName] = obj - }) + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } } - if (Object.keys(rolesMapping).length) { + function removeCertificatesOfAliases(aliasesToRemove) { + const certificates = + getValue(model, '/resources/kubedbComElasticsearch/spec/tls/certificates') || [] + const updatedCertificates = certificates.filter((item) => !aliasesToRemove.includes(item.alias)) commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/rolesMapping', - value: rolesMapping, + path: '/resources/kubedbComElasticsearch/spec/tls/certificates', + value: updatedCertificates, force: true, }) - } else { - // on initial call discriminator value is undefined - // to ignore model$delete for this case, - // roles value checking is required, - // model$delete will be executed only if roles value is not falsy value (empty array) - // and rolesMapping is emptyObject - if (roles) commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/rolesMapping') } -} -function setRolesMapping({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/rolesMapping') - const rolesMapping = getValue(model, '/resources/kubedbComElasticsearch/spec/rolesMapping') + /****** Monitoring *********/ - const roles = [] + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + console.log(configureStatus) - for (const item in rolesMapping) { - rolesMapping[item].roleName = item - roles.push(rolesMapping[item]) + return configureStatus } - setDiscriminatorValue('/rolesMapping', roles) + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + console.log(configureStatus) - return roles -} + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComElasticsearch/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/monitor') + } -function disableRolesEdit({ itemCtx }) { - if (defaultRoles.includes(itemCtx.roleName)) { - return { isEditDisabled: false, isDeleteDisabled: true } + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', + force: true, + }) } - return {} -} -function disableRoleName({ rootModel }) { - return defaultRoles.includes(rootModel && rootModel.roleName) -} + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } -function validateNewRole({ itemCtx }) { - if (defaultRoles.includes(itemCtx.roleName) && itemCtx.isCreate) { - return { isInvalid: true, message: "Can't use this role name" } + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComElasticsearch/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit( + 'wizard/model$delete', + '/resources/kubedbComElasticsearch/spec/monitor/prometheus/exporter', + ) + } } - return {} -} -function getInternalUsers({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/internalUsers') - const internalUsers = getValue(model, '/resources/kubedbComElasticsearch/spec/internalUsers') + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + console.log(path, modelValue) - return Object.keys(internalUsers) -} + return !!modelValue + } -function disableUserDeletion({ itemCtx, rootModel }) { - return itemCtx.value === 'metrics_exporter' && rootModel.roleName === 'readall_and_monitor' -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComElasticsearch/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -// ************************* Kernel Settings ********************************* + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComElasticsearch/spec/metadata/labels') -function onCustomizeKernelSettingChange({ discriminator, getValue, commit }) { - const customizeKernelSettings = getValue(discriminator, '/customizeKernelSettings') + const agent = getValue(model, '/resources/kubedbComElasticsearch/spec/monitor/agent') - if (customizeKernelSettings === 'no') { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/kernelSettings') - } else if (customizeKernelSettings === 'disable') { - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/kernelSettings', - value: {}, - force: true, - }) + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) + } } -} -// ************************** TLS ******************************************* + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComElasticsearch/spec/monitor/agent') -function setApiGroup() { - return 'cert-manager.io' -} + if (!agent) { + removeCertificatesOfAliases(['metrics-exporter']) + } -function setApiGroupEdit({ model, getValue }) { - const kind = getValue(model, '/resources/kubedbComElasticsearch/spec/tls/issuerRef/kind') - const name = getValue(model, '/resources/kubedbComElasticsearch/spec/tls/issuerRef/name') - return kind && name ? 'cert-manager.io' : '' -} + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComElasticsearch/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComElasticsearch/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComElasticsearch/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComElasticsearch/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } + } - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` + + const isKube = !!storeGet('/route/params/actions') + + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/elasticsearchopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` + } + + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } } - try { - const resp = await axios.get(url) + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } - const resources = (resp && resp.data && resp.data.items) || [] + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } + + async function getNamespacedResourceList( axios, storeGet, - getValue, - model, - watchDependency, - }) + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return !!(resp && resp.length) -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - return !resp -} + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComElasticsearch/spec/clusterAuthMode') - return val || 'x509' -} + return ans + } -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComElasticsearch/spec/sslMode') - return val || 'requireSSL' -} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, + }) -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) - } else { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/clusterAuthMode') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/sslMode') } -} -async function showTlsRecommendation({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComElasticsearch/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/issuers` + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') - try { - await axios.get(url, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - return false - } catch (err) { - // if any error response status is 404 or not - if (err.response && err.response.status === 404) { - resp = false - } - console.log(err) - return true - } -} - -async function getAliasOptions({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, -}) { - watchDependency('model#/resources/kubedbComElasticsearch/spec/enableSSL') - watchDependency('model#/resources/kubedbComElasticsearch/spec/monitor') - - const enableSSL = getValue(model, '/resources/kubedbComElasticsearch/spec/enableSSL') - const monitor = getValue(model, '/resources/kubedbComElasticsearch/spec/monitor') - const authPlugin = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - - // always include transport cert alias - const aliases = ['transport'] - - if (authPlugin !== 'X-Pack') { - aliases.push('admin') - } - - if (enableSSL) { - aliases.push('http') - aliases.push('archiver') - if (monitor) { - aliases.push('metrics-exporter') - } - } - - return aliases -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit( - 'wizard/model$delete', - '/resources/kubedbComElasticsearch/spec/monitor/prometheus/exporter', - ) - } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComElasticsearch/spec/init/initialized') - watchDependency('model#/resources/kubedbComElasticsearch/spec/init/initialized') - return !!initialized -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComElasticsearch/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComElasticsearch/spec/init/script') - - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} - -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComElasticsearch/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComElasticsearch/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue( - model, - '/resources/kubedbComElasticsearch/spec/init/script/configMap/name', - ) - const secret = getValue( - model, - '/resources/kubedbComElasticsearch/spec/init/script/secret/secretName', - ) - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/init/script/secret') - - if ( - !valueExists(model, getValue, '/resources/kubedbComElasticsearch/spec/init/script/configMap') - ) { - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/init/script/configMap') - - if ( - !valueExists(model, getValue, '/resources/kubedbComElasticsearch/spec/init/script/secret') - ) { - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} - -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) - } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule bakcup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComElasticsearchAnnotations = - getValue(model, '/resources/kubedbComElasticsearch/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComElasticsearchAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - } -} - -function deleteKubedbComElasticsearchDbAnnotation(getValue, model, commit) { - const annotations = - getValue(model, '/resources/kubedbComElasticsearch/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubedbComElasticsearchDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = - getValue(model, '/resources/kubedbComElasticsearch/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComElasticsearch annotation - deleteKubedbComElasticsearchDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -async function initBackupData({ storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComElasticsearch') - initialDbMetadata = objectCopy(dbResource.metadata) - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // set backup switch here - isBackupOn = !!config - - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends - - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` - - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions - } - - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, - } - - setDiscriminatorValue('isBackupDataLoaded', true) -} - -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} - -async function setBackupType() { - return 'BackupConfig' -} - -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - return arr -} - -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), - force: true, - }) - } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch', - value: objectCopy(dbResource), - force: true, - }) -} - -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') - - return selectedType === type -} - -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations - - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} - -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} - -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} - -function onArchiverChange({ getValue, discriminator, commit }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComElasticsearch/spec/archiver' - if (archiverSwitch) { - commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, - }) - } else { - commit('wizard/model$delete', path) - } -} - -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) - - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' - } - - commit('wizard/model$update', { - path: `/resources/kubedbComElasticsearch/metadata/${type}`, - value: obj, - force: true, - }) -} - -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] - - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] - - commit('wizard/model$update', { - path: `/resources/kubedbComElasticsearch/metadata/${type}`, - value: obj, - force: true, - }) -} - -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} - -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, - force: true, - }) - } -} - -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} - -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} - -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} - -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} - -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComElasticsearch/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubedbComElasticsearchDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubedbComElasticsearchDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = - getValue(model, '/resources/kubedbComElasticsearch/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComElasticsearch/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComElasticsearch/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComElasticsearch/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComElasticsearch/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComElasticsearch/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_user_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComElasticsearch/spec/monitor/agent') - - if (!agent) { - removeCertificatesOfAliases({ model, getValue, commit }, ['metrics-exporter']) - } - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -//////////////////// service monitor /////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_user_config') - commit('wizard/model$delete', '/resources/config_secret') - } else { - const value = getValue(model, '/resources/secret_user_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_user_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_user_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setConfigFiles({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/secret_user_config/stringData') - const configFiles = getValue(model, '/resources/secret_user_config/stringData') - - const files = [] - - for (const item in configFiles) { - const obj = {} - obj.key = item - obj.value = configFiles[item] - files.push(obj) - } - - setDiscriminatorValue('/configFiles', files) - - return files -} - -function onConfigFilesChange({ discriminator, getValue, commit }) { - const files = getValue(discriminator, '/configFiles') - - const configFiles = {} - - if (files) { - files.forEach((item) => { - const { key, value } = item - configFiles[key] = value - }) - } - - commit('wizard/model$update', { - path: '/resources/secret_user_config/stringData', - value: configFiles, - force: true, - }) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_user_config') - } -} - -function initSetCustomConfig({ model, getValue }) { - const configSecret = getValue(model, '/resources/kubedbComElasticsearch/spec/configSecret/name') - - if (configSecret) return 'yes' - else return 'no' -} - -//////////////////// secret custom config ///////////////// -function onSecretConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_secure_config') - } else { - const value = getValue(model, '/resources/secret_secure_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_secure_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-secure-config` - commit('wizard/model$update', { - path: '/resources/kubedbComElasticsearch/spec/secureConfigSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function setSecretConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_secure_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigFiles({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/secret_secure_config/stringData') - const configFiles = getValue(model, '/resources/secret_secure_config/stringData') - - const files = [] - - for (const item in configFiles) { - const obj = {} - obj.key = item - obj.value = configFiles[item] - files.push(obj) - } - - setDiscriminatorValue('/configFiles', files) - - return files -} - -function onSecretConfigFilesChange({ discriminator, getValue, commit }) { - const files = getValue(discriminator, '/configFiles') - - const configFiles = {} - - if (files) { - files.forEach((item) => { - const { key, value } = item - configFiles[key] = value - }) - } - - commit('wizard/model$update', { - path: '/resources/secret_secure_config/stringData', - value: configFiles, - force: true, - }) -} - -function onSetSecretCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setSecretCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComElasticsearch/spec/secureConfigSecret') - commit('wizard/model$delete', '/resources/secret_secure_config') - } -} - -function initSetSecureCustomConfig({ model, getValue }) { - const configSecret = getValue( - model, - '/resources/kubedbComElasticsearch/spec/secureConfigSecret/name', - ) - - if (configSecret) return 'yes' - else return 'no' -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/elasticsearchopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} - -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} - -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} + if (!configMapName) return [] -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) - } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` + const configMaps = (resp && resp.data && resp.data.data) || {} - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data + return configMapKeys + } catch (e) { + console.log(e) + return [] } - } catch (e) { - console.log(e) } - return [] -} - -function initBlueprint() { - return 'create' -} -function initUsagePolicy() { - return 'Same' -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -////////////////// auto scaler ////////////// -let autoscaleType = '' -let dbDetails = {} + const secrets = (resp && resp.data && resp.data.items) || [] -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: namespace, - force: true, + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency( - 'model#/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', - ) - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue( + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( model, - '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', - ) && !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/metadata/namespace') - const namespace = getValue(model, '/metadata/namespace') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/elasticsearches`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] + '/resources/kubedbComElasticsearch/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -async function getDbDetails({ setDiscriminatorValue, commit, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' - const name = - storeGet('/route/params/name') || - getValue( - model, - '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', - ) || - '' + if (!secretName) return [] - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/elasticsearches/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) - } - } - - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingkubedbComElasticsearchAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingkubedbComElasticsearchAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} -async function dbTypeEqualsTo({ axios, storeGet, watchDependency, model, getValue, commit }, type) { - watchDependency('discriminator#/dbDetails') + const secret = (resp && resp.data && resp.data.data) || {} - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else verd = 'node' - clearSpecModel({ commit }, verd) - return type === verd && spec -} + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'node') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/${autoscaleType}/data`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/${autoscaleType}/ingest`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/${autoscaleType}/master`, - ) - } else if (dbtype === 'topology') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/${autoscaleType}/node`, - ) + return secretKeys + } catch (e) { + console.log(e) + return [] + } } -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue( - model, - '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', - ) || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from model - if (type === 'compute') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/storage', - ) - if (type === 'storage') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute', - ) -} -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue(model, '/metadata/namespace') - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', - ) + function returnFalse() { + return false } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency( - 'model#/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', - ) - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} - -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + function setValueFromDbDetails(path) { + const value = getValue(model, path) + console.log({ value }) + return value } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, - }) - } + function isKubedb() { + return !!storeGet('/route/params/actions') } -} - -function objectCopy(obj) { - const temp = JSON.stringify(obj) - return JSON.parse(temp) -} - -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComElasticsearchBinding') - 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 labels = getValue(model, '/resources/kubedbComElasticsearch/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'ElasticsearchBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { - name: dbName, - namespace: dbNamespace, - }, - }, + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency( + // 'model#/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', + // ) + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) } - if (value) { - await commit('wizard/model$update', { - path: '/resources/catalogAppscodeComElasticsearchBinding', - value: bindingValues, - force: true, - }) - } else { - await commit('wizard/model$delete', '/resources/catalogAppscodeComElasticsearchBinding') + function setApplyToIfReady() { + return 'IfReady' } -} -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) - - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` const resp = await axios.get(url) - - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList } catch (e) { console.log(e) - return [] } + return [] } -} -function setAllowedMachine({ model, getValue }, type, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComElasticsearchAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length } - const machine = parsedInstance[type] || '' - const mx = machine?.includes(',') ? machine.split(',')[1] : '' - const mn = machine?.includes(',') ? machine.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, type, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${type}-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }, type) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComElasticsearchAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComElasticsearchAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - - const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) - const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) - const minMaxMachine = `${minMachine},${maxMachine}` - - parsedInstance[type] = minMaxMachine - const instanceString = JSON.stringify(parsedInstance) - annotations['kubernetes.io/instance-type'] = instanceString - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComElasticsearchAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== instanceString) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + return { + returnFalse, + initScheduleBackup, + initScheduleBackupForEdit, + onScheduleBackupChange, + showBackupForm, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + onBackupTypeChange, + isBackupType, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showConfigList, + showSchedule, + showScheduleBackup, + getDefaultSchedule, + onInputChangeSchedule, + // binding + addOrRemoveBinding, + isBindingAlreadyOn, + // storage + handleUnit, + // compute + getDbDetails, + isConsole, + getNamespaces, + initMetadata, + fetchTopologyMachines, + setTrigger, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + setControlledResources, + dbTypeEqualsTo, + // monitoring + isEqualToModelPathValue, + getResources, + removeCertificatesOfAliases, + showMonitoringSection, + onEnableMonitoringChange, + showCustomizeExporterSection, + onCustomizeExporterChange, + isValueExistInModel, + onNamespaceChange, + onLabelChange, + onAgentChange, + getOpsRequestUrl, + setValueFrom, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + onValueFromChange, + isEqualToValueFromType, + getNamespacedResourceList, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + + setValueFromDbDetails, + showOpsRequestOptions, + isKubedb, + setApplyToIfReady, + fetchNodeTopology, + isNodeTopologySelected, + isRancherManaged, } } - -return { - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - isDedicatedModeSelected, - isCombinedModeSelected, - isDiscriminatorEqualTo, - isAuthPluginNotSearchGuard, - showInternalUsersAndRolesMapping, - showSecureCustomConfig, - getElasticSearchVersions, - isSecurityEnabled, - onDisableSecurityChange, - onVersionChange, - onEnableSSLChange, - removeCertificatesOfAliases, - setDatabaseMode, - getStorageClassNames, - getStorageClassNamesFromDiscriminator, - deleteDatabaseModePath, - isEqualToDatabaseMode, - getSelectedVersionAuthPlugin, - onNodeSwitchFalse, - hasTopologyNode, - hideNode, - disableNode, - setInitialStatusFalse, - onInternalUsersChange, - disableRoleDeletion, - setInternalUsers, - validateNewUser, - disableUsername, - disableUserEdit, - isAuthPluginEqualTo, - showExistingCredSection, - showPasswordCredSection, - onRolesMappingChange, - setRolesMapping, - disableRolesEdit, - disableRoleName, - validateNewRole, - disableUserDeletion, - onCustomizeKernelSettingChange, - getInternalUsers, - setApiGroup, - setApiGroupEdit, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - showTlsRecommendation, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubedbComElasticsearchDbAnnotation, - addKubedbComElasticsearchDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - setAuthSecretPassword, - onAuthSecretPasswordChange, - showSecretSection, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - setConfigurationSource, - getMaxUnavailableOptions, - setConfigFiles, - onConfigFilesChange, - onSetCustomConfigChange, - onSecretConfigurationSourceChange, - setSecretConfigurationSource, - setSecretConfigFiles, - onSecretConfigFilesChange, - onSetSecretCustomConfigChange, - initSetCustomConfig, - initSetSecureCustomConfig, - getOpsRequestUrl, - getCreateNameSpaceUrl, - isVariantAvailable, - setStorageClass, - - initBackupData, - setBackupType, - getTypes, - isBackupDataLoadedTrue, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, -} diff --git a/charts/kubedbcom-ferretdb-editor-options/ui/create-ui.yaml b/charts/kubedbcom-ferretdb-editor-options/ui/create-ui.yaml index 96e027e220..83bd9dfd77 100644 --- a/charts/kubedbcom-ferretdb-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-ferretdb-editor-options/ui/create-ui.yaml @@ -1,369 +1,361 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/FerretDB/versions + if: + type: function + name: isToggleOn|databases/FerretDB/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/FerretDB/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/FerretDB/mode + loader: getAdminOptions|databases/FerretDB/mode + if: + type: function + name: isToggleOn|databases/FerretDB/mode + label: Database mode + isHorizontal: true + watcher: + func: onModeChange + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - elements: + - label: Replicaset number + schema: schema/properties/spec/properties/server/properties/primary/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/server/properties/primary/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|server/primary + if: + type: function + name: isMachineCustom|server/primary + label: cpu + watcher: + func: setRequests|cpu|server/primary + paths: + - schema/properties/spec/properties/server/properties/primary/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/server/properties/primary/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|server/primary + if: + type: function + name: isMachineCustom|server/primary + label: memory + watcher: + func: setRequests|memory|server/primary + paths: + - schema/properties/spec/properties/server/properties/primary/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/server/properties/primary/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Primary + showLabels: true + type: block-layout + - elements: + - label: Replicaset number + schema: schema/properties/spec/properties/server/properties/secondary/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/server/properties/secondary/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|server/secondary + if: + type: function + name: isMachineCustom|server/secondary + label: cpu + watcher: + func: setRequests|cpu|server/secondary + paths: + - schema/properties/spec/properties/server/properties/secondary/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/server/properties/secondary/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|server/secondary + if: + type: function + name: isMachineCustom|server/secondary + label: memory + watcher: + func: setRequests|memory|server/secondary + paths: + - schema/properties/spec/properties/server/properties/secondary/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/server/properties/secondary/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: isEqualToModelPathValue|PrimaryAndSecondary|/spec/mode + label: Secondary + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - elements: + - label: Storage size + schema: schema/properties/spec/properties/backend/properties/persistence/properties/size + type: input + - label: Replicaset number + schema: schema/properties/spec/properties/backend/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/backend/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|backend + if: + type: function + name: isMachineCustom|backend + label: cpu + watcher: + func: setRequests|cpu|backend + paths: + - schema/properties/spec/properties/backend/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/backend/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|backend + if: + type: function + name: isMachineCustom|backend + label: memory + watcher: + func: setRequests|memory|backend + paths: + - schema/properties/spec/properties/backend/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/backend/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Backend + showLabels: true + type: block-layout + - description: Configure Credentials, Deployment Mode etc. elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/FerretDB/versions - if: isToggleOn|databases/FerretDB/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/FerretDB/properties/versions/properties/default + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name type: select - - computed: getDefault|databases/FerretDB/mode - fetch: getAdminOptions|databases/FerretDB/mode - hasDescription: true - if: isToggleOn|databases/FerretDB/mode - label: - text: labels.database.mode - onChange: onModeChange - schema: - $ref: schema#/properties/spec/properties/mode + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default type: radio - - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/server/properties/primary/properties/replicas - type: input - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/server/properties/primary/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|server/primary - disabled: isMachineNotCustom - if: isMachineCustom|server/primary - label: - text: labels.cpu - onChange: setRequests|cpu|server/primary - schema: - $ref: schema#/properties/spec/properties/server/properties/primary/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|server/primary - disabled: isMachineNotCustom - if: isMachineCustom|server/primary - label: - text: labels.memory - onChange: setRequests|memory|server/primary - schema: - $ref: schema#/properties/spec/properties/server/properties/primary/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: Primary - show_label: true - type: single-step-form - - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/server/properties/secondary/properties/replicas - type: input - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/server/properties/secondary/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|server/secondary - disabled: isMachineNotCustom - if: isMachineCustom|server/secondary - label: - text: labels.cpu - onChange: setRequests|cpu|server/secondary - schema: - $ref: schema#/properties/spec/properties/server/properties/secondary/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|server/secondary - disabled: isMachineNotCustom - if: isMachineCustom|server/secondary - label: - text: labels.memory - onChange: setRequests|memory|server/secondary - schema: - $ref: schema#/properties/spec/properties/server/properties/secondary/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - if: isEqualToModelPathValue|PrimaryAndSecondary|/spec/mode - label: - text: Secondary - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/backend/properties/persistence/properties/size - type: input - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/backend/properties/replicas - type: input - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/backend/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|backend - disabled: isMachineNotCustom - if: isMachineCustom|backend - label: - text: labels.cpu - onChange: setRequests|cpu|backend - schema: - $ref: schema#/properties/spec/properties/backend/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|backend - disabled: isMachineNotCustom - if: isMachineCustom|backend - label: - text: labels.memory - onChange: setRequests|memory|backend - schema: - $ref: schema#/properties/spec/properties/backend/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: Backend - show_label: true - type: single-step-form - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - backend: - default: {} - type: object - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret + - init: + type: func + value: setMonitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - elements: + - init: + type: func + value: checkHostnameOrIP + if: + type: function + name: isToggleOn|tls + label: Enable TLS? + watcher: + func: checkHostnameOrIP + paths: + - schema/properties/spec/properties/admin/properties/tls/properties/default + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + type: block-layout + - elements: + - init: + type: func + value: checkHostnameOrIP + label: Expose via Gateway? + watcher: + func: checkHostnameOrIP + paths: + - schema/properties/spec/properties/admin/properties/expose/properties/default + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - if: isToggleOn|monitoring - type: single-step-form - - elements: - - computed: checkHostnameOrIP - if: isToggleOn|tls - label: - text: Enable TLS? - onChange: checkHostnameOrIP - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - elements: - - computed: checkHostnameOrIP - label: - text: Expose via Gateway? - onChange: checkHostnameOrIP - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - if: isToggleOn|expose - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|expose + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-ferretdb-editor-options/ui/functions.js b/charts/kubedbcom-ferretdb-editor-options/ui/functions.js index 8b62a4df00..573fc0b8a6 100644 --- a/charts/kubedbcom-ferretdb-editor-options/ui/functions.js +++ b/charts/kubedbcom-ferretdb-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,941 +317,957 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function onModeChange({ model, getValue, commit }) { - const dbMode = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/replicas', - value: dbMode === 'Replicaset' ? 3 : 1, - force: true, - }) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + function onModeChange() { + const dbMode = getValue(model, '/spec/mode') + commit('wizard/model$update', { + path: '/spec/replicas', + value: dbMode === 'Replicaset' ? 3 : 1, + force: true, }) - } else { - array = machineList - .map((machine) => { + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) - commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, - force: true, - }) + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: commitPath, + value: val, force: true, }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + if (val === 'capz' && ifDedicated()) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) - } -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] } else { - return resp.data?.status?.namespaces || [] + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] } - } catch (e) { - console.log(e) - } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -let hostName = '' -let ip = '' -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const gatewayinfosurl = `/clusters/${owner}/${cluster}/proxy/meta.k8s.appscode.com/v1alpha1/gatewayinfos/${namespace}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - const gatewayinfosResp = await axios.get(gatewayinfosurl) - hostName = gatewayinfosResp.data?.spec?.hostName - ip = gatewayinfosResp.data?.spec?.ip - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/FerretDB/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/FerretDB/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/FerretDB/mode/available') || [] - if (arr.length) defMode = arr[0] + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + return [] } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) - } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - setDiscriminatorValue('/bundleApiLoaded', true) -} + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let hostName = '' + let ip = '' + + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const gatewayinfosurl = `/clusters/${owner}/${cluster}/proxy/meta.k8s.appscode.com/v1alpha1/gatewayinfos/${namespace}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + const gatewayinfosResp = await axios.get(gatewayinfosurl) + hostName = gatewayinfosResp.data?.spec?.hostName + ip = gatewayinfosResp.data?.spec?.ip + } catch (e) { + console.log(e) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - return returnArray -} + if (!getValue(model, `/spec/admin/databases/FerretDB/mode/toggle`)) { + let defMode = getDefault('databases/FerretDB/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/FerretDB/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + setDiscriminatorValue('/bundleApiLoaded', true) } - return options -} - -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') + const options = getValue(model, `/spec/admin/${type}/available`) || [] - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + return options + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } -} -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function updateAlertValue({ commit, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function onRefChange({ discriminator, getValue, commit }, type) { - const ref = getValue(discriminator, `/${type}`) || {} - commit('wizard/model$update', { - path: `/spec/${type}/name`, - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: `/spec/${type}/namespace`, - value: ref.namespace || '', - force: true, - }) -} + function onRefChange(type) { + const ref = getValue(discriminator, `/${type}`) || {} + commit('wizard/model$update', { + path: `/spec/${type}/name`, + value: ref.name || '', + force: true, + }) + commit('wizard/model$update', { + path: `/spec/${type}/namespace`, + value: ref.namespace || '', + force: true, + }) + } -function isExternallyManaged( - { getValue, model, watchDependency, commit, setDiscriminatorValue }, - type, -) { - watchDependency(`model#/spec/${type}/externallyManaged`) - const isManaged = getValue(model, `/spec/${type}/externallyManaged`) || false - if (!isManaged) clearRefs({ commit, setDiscriminatorValue }, type) - return isManaged -} + function isExternallyManaged(type) { + // watchDependency(`model#/spec/${type}/externallyManaged`) + const isManaged = getValue(model, `/spec/${type}/externallyManaged`) || false + if (!isManaged) clearRefs(type) + return isManaged + } -function clearRefs({ commit, setDiscriminatorValue }, type) { - setDiscriminatorValue(`/${type}`, '') - commit('wizard/model$update', { - path: `/spec/${type}/name`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/spec/${type}/namespace`, - value: '', - force: true, - }) -} + function clearRefs(type) { + setDiscriminatorValue(`/${type}`, '') + commit('wizard/model$update', { + path: `/spec/${type}/name`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/spec/${type}/namespace`, + value: '', + force: true, + }) + } -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, + async function getAppBindings(type) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const queryParams = { + filter: { + items: { + metadata: { name: null, namespace: null }, + spec: { type: null }, + }, }, - }, + } + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + queryParams, + ) + const resources = (resp && resp.data && resp.data.items) || [] + + const fileredResources = resources + .filter((item) => item.spec?.type === `kubedb.com/${type}`) + .map((item) => { + const name = item.metadata?.name || '' + const namespace = item.metadata?.namespace || '' + return { + text: `${namespace}/${name}`, + value: { + name: name, + namespace: namespace, + }, + } + }) + return fileredResources + } catch (e) { + console.log(e) + return [] + } } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, - ) - const resources = (resp && resp.data && resp.data.items) || [] - - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] + + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length } -} -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] - } + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -async function checkHostnameOrIP({ commit, model, getValue }) { - const tls = getValue(model, '/spec/admin/tls/default') - const expose = getValue(model, '/spec/admin/expose/default') - if (tls && expose) { - if (hostName) { + function checkHostnameOrIP() { + const tls = getValue(model, '/spec/admin/tls/default') + const expose = getValue(model, '/spec/admin/expose/default') + if (tls && expose) { + if (hostName) { + commit('wizard/model$update', { + path: '/spec/hostName', + value: hostName, + force: true, + }) + } else { + commit('wizard/model$update', { + path: '/spec/ip', + value: ip, + force: true, + }) + } + } else { commit('wizard/model$update', { path: '/spec/hostName', - value: hostName, + value: '', force: true, }) - } else { commit('wizard/model$update', { path: '/spec/ip', - value: ip, + value: '', force: true, }) } - } else { - commit('wizard/model$update', { - path: '/spec/hostName', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/ip', - value: '', - force: true, - }) } -} -return { - checkHostnameOrIP, - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - showAdditionalSettings, - initBundle, - returnFalse, - isVariantAvailable, - showAuthPasswordField, - isEqualToModelPathValue, - onModeChange, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - getNamespaces, - isToggleOn, - getAdminOptions, - getNodeTopology, - isMachineNotCustom, - isMachineCustom, - onAuthChange, - clearConfiguration, - isConfigDatabaseOn, - showIssuer, - setMonitoring, - updateAlertValue, - showAlerts, - onBackupSwitch, - onRefChange, - isExternallyManaged, - clearRefs, - getAppBindings, - setBackup, - getDefault, + return { + checkHostnameOrIP, + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + showAdditionalSettings, + initBundle, + returnFalse, + isVariantAvailable, + showAuthPasswordField, + isEqualToModelPathValue, + onModeChange, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + getNamespaces, + isToggleOn, + getAdminOptions, + getNodeTopology, + filterNodeTopology, + isMachineNotCustom, + isMachineCustom, + onAuthChange, + clearConfiguration, + isConfigDatabaseOn, + showIssuer, + setMonitoring, + updateAlertValue, + showAlerts, + onBackupSwitch, + onRefChange, + isExternallyManaged, + clearRefs, + getAppBindings, + setBackup, + getDefault, + } } diff --git a/charts/kubedbcom-ferretdb-editor/ui/edit-ui.yaml b/charts/kubedbcom-ferretdb-editor/ui/edit-ui.yaml index f29720e6d2..b5a67fb079 100644 --- a/charts/kubedbcom-ferretdb-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-ferretdb-editor/ui/edit-ui.yaml @@ -1,556 +1,543 @@ -steps: -- form: - discriminator: - dbDetails: - default: false - type: boolean +type: multi-step-form +step: + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails + elements: + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType + options: + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines + elements: + # primary + - type: block-layout + label: Primary + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComFerretDBAutoscaler/spec/compute/primary/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-primary-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|primary|min + loader: + name: getMachines|primary|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-primary-max + watcher: + func: onMachineChange|primary + paths: + - temp/properties/allowedMachine-primary-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-primary-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|primary|max + loader: + name: getMachines|primary|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-primary-min + watcher: + func: onMachineChange|primary + paths: + - temp/properties/allowedMachine-primary-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|primary + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/controlledResources + + # secondary + - type: block-layout + label: Secondary + if: + type: function + name: ferretTypeEqualsTo|secondary + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComFerretDBAutoscaler/spec/compute/secondary/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-secondary-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|secondary|min + loader: + name: getMachines|secondary|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-secondary-max + watcher: + func: onMachineChange|secondary + paths: + - temp/properties/allowedMachine-secondary-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-secondary-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|secondary|max + loader: + name: getMachines|secondary|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-secondary-min + watcher: + func: onMachineChange|secondary + paths: + - temp/properties/allowedMachine-secondary-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|secondary + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComFerretDB/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComFerretDBAutoscaler/spec/compute/primary/trigger - label: - text: Trigger + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-primary-max: - type: string - allowedMachine-primary-min: - type: string + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComFerretDB/spec/monitor/agent elements: - - computed: setAllowedMachine|primary|min - disableUnselect: true - fetch: getMachines|primary|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|primary - schema: - $ref: discriminator#/properties/allowedMachine-primary-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|primary|max - disableUnselect: true - fetch: getMachines|primary|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|primary - schema: - $ref: discriminator#/properties/allowedMachine-primary-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|primary - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary/properties/controlledResources - type: multiselect - label: - text: Primary - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/primary - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComFerretDBAutoscaler/spec/compute/secondary/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-secondary-max: - type: string - allowedMachine-secondary-min: - type: string + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComFerretDB/spec/monitor/agent elements: - - computed: setAllowedMachine|secondary|min - disableUnselect: true - fetch: getMachines|secondary|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|secondary - schema: - $ref: discriminator#/properties/allowedMachine-secondary-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|secondary|max - disableUnselect: true - fetch: getMachines|secondary|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|secondary - schema: - $ref: discriminator#/properties/allowedMachine-secondary-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|secondary - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary/properties/controlledResources - type: multiselect - if: ferretTypeEqualsTo|secondary - label: - text: Secondary - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/secondary - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComFerretDBAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComFerretDB/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComFerretDB/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComFerretDB/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComFerretDB/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComFerretDB/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -type: multi-step-form + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComFerretDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true \ No newline at end of file diff --git a/charts/kubedbcom-ferretdb-editor/ui/functions.js b/charts/kubedbcom-ferretdb-editor/ui/functions.js index a2a116e2fa..7b4961e8c0 100644 --- a/charts/kubedbcom-ferretdb-editor/ui/functions.js +++ b/charts/kubedbcom-ferretdb-editor/ui/functions.js @@ -1,2215 +1,863 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} -function setAddressType({ model, getValue }) { - const value = getValue(model, '/resources/kubedbComFerretDB/spec/useAddressType') - - if (!value) { - return 'DNS' - } - - return value -} - -// ************************* Basic Info ********************************************** -async function getFerretDBVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] - } -} - -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue }) { - const replicas = getValue(model, '/resources/kubedbComFerretDB/spec/replicas') - - return replicas === 1 ? 'Standalone' : 'Cluster' -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} - -const onDatabaseModeChange = ({ discriminator, getValue, commit }) => { - const databaseMode = getValue(discriminator, '/activeDatabaseMode') - - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/replicas', - value: databaseMode === 'Standalone' ? 1 : 3, - force: true, - }) -} - -// ************************** TLS ******************************88 - -function setApiGroup() { - return 'cert-manager.io' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComFerretDB/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComFerretDB/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComFerretDB/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComFerretDB/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } - - if (!url) return [] - - try { - const resp = await axios.get(url) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComFerretDB/spec/sslMode') - return val || 'require' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/monitor/prometheus/exporter') - } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComFerretDB/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComFerretDB/spec/init/script') - - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} - -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComFerretDB/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( model, - '/resources/stashAppscodeComRestoreSession_init', + store.state, ) - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComFerretDB/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + let autoscaleType = '' + let dbDetails = {} + + function isConsole() { + const isKube = isKubedb() + + if (isKube) { + const dbName = storeGet('/route/params/name') || '' commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', + path: '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name', value: dbName, force: true, }) - } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComFerretDB/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComFerretDB/spec/init/script/secret/secretName') - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/init/script/secret') - - if (!valueExists(model, getValue, '/resources/kubedbComFerretDB/spec/init/script/configMap')) { - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComFerretDB/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} - -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) - } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule bakcup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComFerretDBAnnotations = - getValue(model, '/resources/kubedbComFerretDB/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComFerretDBAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - } -} - -function deleteKubeDbComFerretDBDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComFerretDB/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubeDbComFerretDBDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComFerretDB/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComFerretDB annotation - deleteKubeDbComFerretDBDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -// invoker form -function initBackupInvoker({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration) return 'backupConfiguration' - else if (isBluePrint) return 'backupBlueprint' - else return undefined -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model }) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - - if (backupInvoker === 'backupConfiguration') { - // delete annotation and create backup config object - deleteKubeDbComFerretDBDbAnnotation(getValue, model, commit) - const dbName = getValue(model, '/metadata/release/name') - - if (!valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - // delete backup configuration object and create the annotation - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - addKubeDbComFerretDBDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - '', - ) - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComFerretDB/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComFerretDBDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComFerretDBDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComFerretDB/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComFerretDB/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComFerretDB/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComFerretDB/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComFerretDB/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComFerretDB/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, + path: '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/name', + value: modifiedName, force: true, }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) + return !isKube + } + + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name') || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/ferretdbs/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } } - } - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/configSecret/name', - value: `${dbName}-config`, + path: `/metadata/release/name`, + value: name, force: true, }) - } - - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, + path: `/metadata/release/namespace`, + value: namespace, force: true, }) - } - - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, + path: `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name`, + value: name, force: true, }) - } - - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, + path: `/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, force: true, }) } -} -function returnFalse() { - return false -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComFerretDB/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, }) - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComFerretDB/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') + const resources = (resp && resp.data && resp.data.items) || [] - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') } -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComFerretDB/spec/init/initialized') - watchDependency('model#/resources/kubedbComFerretDB/spec/init/initialized') - return !!initialized -} -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - if (owner && cluster && namespace) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, - }, - }, - }, - }, - ) - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) - }) + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - return [] -} -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name') || + '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, + path: '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/name', + value: modifiedName, force: true, }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/configSecret/name', - value: configSecretName, - force: true, - }) + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute', + ) } -} -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/user.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} + async function fetchTopologyMachines() { + const instance = hasAnnotations() -function onConfigurationChangeEdit({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - - commit('wizard/model$update', { - path: '/resources/secret_config/data/ferretdb.ini', - value: btoa(value), - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } - return 'use-existing-config' -} -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/user.conf') -} + function hasAnnotations(type) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] -function setConfigurationForEdit({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/ferretdb.ini') - return atob(value) -} + return !!instance + } -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/user.conf') - return atob(value) -} + function setAllowedMachine(type, minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') + const machine = parsedInstance[type] || '' + const mx = machine?.includes(',') ? machine.split(',')[1] : '' + const mn = machine?.includes(',') ? machine.split(',')[0] : '' - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') + if (minmax === 'min') return mn + else return mx } -} -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/ferretdbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} + async function getMachines(type, minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${type}-${depends}` -const getAppbinding = async ({ axios, storeGet, getValue, watchDependency, rootModel }) => { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - const group = 'appcatalog.appscode.com' - const version = 'v1alpha1' - const resource = 'appbindings' + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - watchDependency('rootModel#/databaseRef/namespace') + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - const namespace = getValue(rootModel, '/databaseRef/namespace') + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - const resources = (resp && resp.data && resp.data.items) || [] + return dependantIndex === -1 ? machines : filteredMachine + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) + const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) + const minMaxMachine = `${minMachine},${maxMachine}` -function onRefChange({ discriminator, getValue, commit }) { - const ref = getValue(discriminator, '/pgRef') || {} - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/database/databaseRef/name', - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComFerretDB/spec/database/databaseRef/namespace', - value: ref.namespace || '', - force: true, - }) -} + parsedInstance[type] = minMaxMachine + const instanceString = JSON.stringify(parsedInstance) + annotations['kubernetes.io/instance-type'] = instanceString -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, - }, - }, - } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, - ) - const resources = (resp && resp.data && resp.data.items) || [] + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute/${type}` - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } + if (minMachine && maxMachine && instance !== instanceString) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, }) - return fileredResources - } catch (e) { - console.log(e) - return [] + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: annotations, + force: true, + }) + } } -} - -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + function hasNoAnnotations() { + return !hasAnnotations() + } - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] + function setAllowedMachine(type, minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + + const machine = parsedInstance[type] || '' + const mx = machine?.includes(',') ? machine.split(',')[1] : '' + const mn = machine?.includes(',') ? machine.split(',')[0] : '' + + if (minmax === 'min') return mn + else return mx + } + + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute/${type}/controlledResources` commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/name', - value: modifiedName, + path: path, + value: list, force: true, }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace', - value: namespace, - force: true, + return list + } + + function ferretTypeEqualsTo(param) { + const dbDetails = getValue(model, '/resources/kubedbComFerretDB') + const type = dbDetails.spec?.server?.secondary ? 'secondary' : 'primary' + return param === type + } + + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name }) + return mappedList + } catch (e) { + console.log(e) } + return [] } - return !isKube -} + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) + } -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} + function setApplyToIfReady() { + return 'IfReady' + } -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isKubedb() { + return !!storeGet('/route/params/actions') + } -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + /********** Monitoring ***********/ - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } - const resources = (resp && resp.data && resp.data.items) || [] + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resources = (resp && resp.data && resp.data.items) || [] - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } - const resources = (resp && resp.data && resp.data.items) || [] + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { + let ans = [] try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/ferretdbs/${name}`, - ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items } catch (e) { console.log(e) } + + return ans } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, + }) -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - clearSpecModel({ commit }, verd) - return type === verd && spec -} -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/${autoscaleType}/cluster`, - ) + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus } -} -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComFerretDB/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/monitor') + } + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/name', - value: modifiedName, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) - - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name', - ) } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComFerretDB/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComFerretDB/spec/monitor/prometheus/exporter') + } } - return [] -} -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComFerretDB/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComFerretDB/spec/metadata/labels') -function setApplyToIfReady() { - return 'IfReady' -} + const agent = getValue(model, '/resources/kubedbComFerretDB/spec/monitor/agent') -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, force: true, }) } - } else { - if (!isNaN(value)) { - value += 'Gi' + } + + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComFerretDB/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], force: true, }) + + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } } -} -function ferretTypeEqualsTo({ getValue, model }, param) { - const dbDetails = getValue(model, '/resources/kubedbComFerretDB') - const type = dbDetails.spec?.server?.secondary ? 'secondary' : 'primary' - return param === type -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + if (owner && cluster && namespace) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { + items: { + data: { username: null, password: null }, + metadata: { name: null }, + type: null, + }, + }, + }, + }, + ) + + const secrets = (resp && resp.data && resp.data.items) || [] + + const filteredSecrets = secrets.filter((item) => { + const validType = [ + 'kubernetes.io/service-account-token', + 'Opaque', + 'kubernetes.io/basic-auth', + ] + return validType.includes(item.type) + }) + + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + } + } + return [] + } -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const isKube = !!storeGet('/route/params/actions') - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/ferretdbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } + + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComFerretDBAutoscaler/spec/databaseRef/name', + ) } } -} -function setAllowedMachine({ model, getValue }, type, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } } - const machine = parsedInstance[type] || '' - const mx = machine?.includes(',') ? machine.split(',')[1] : '' - const mn = machine?.includes(',') ? machine.split(',')[0] : '' + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } + } - if (minmax === 'min') return mn - else return mx -} + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getMachines({ getValue, watchDependency, discriminator }, type, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${type}-${depends}` + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComFerretDB/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + if (!configMapName) return [] - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) + const configMaps = (resp && resp.data && resp.data.data) || {} - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - return dependantIndex === -1 ? machines : filteredMachine -} + return configMapKeys + } catch (e) { + console.log(e) + return [] + } + } -function hasAnnotations({ model, getValue }, type) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComFerretDB/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) - return !!instance -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} + if (!secretName) return [] -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComFerretDBAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) - const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) - const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) - const minMaxMachine = `${minMachine},${maxMachine}` + const secret = (resp && resp.data && resp.data.data) || {} - parsedInstance[type] = minMaxMachine - const instanceString = JSON.stringify(parsedInstance) - annotations['kubernetes.io/instance-type'] = instanceString + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComFerretDBAutoscaler/spec/compute/${type}` + return secretKeys + } catch (e) { + console.log(e) + return [] + } + } - if (minMachine && maxMachine && instance !== instanceString) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + function returnFalse() { + return false } -} -return { - isRancherManaged, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - isVariantAvailable, - fetchJsons, - getAppbinding, - onDatabaseModeChange, - setDatabaseMode, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - setAddressType, - getFerretDBVersions, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - valueExists, - onConfigurationChangeEdit, - setConfigurationForEdit, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComFerretDBDbAnnotation, - addKubeDbComFerretDBDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - setConfigurationForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - disableInitializationSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - onRefChange, - getAppBindings, - ferretTypeEqualsTo, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + return { + isConsole, + getDbDetails, + getNamespaces, + isRancherManaged, + onNamespaceChange, + getDbs, + initMetadata, + fetchTopologyMachines, + setTrigger, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + setControlledResources, + ferretTypeEqualsTo, + fetchNodeTopology, + isNodeTopologySelected, + showOpsRequestOptions, + setApplyToIfReady, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + } } diff --git a/charts/kubedbcom-hazelcast-editor-options/ui/create-ui.yaml b/charts/kubedbcom-hazelcast-editor-options/ui/create-ui.yaml index 53cb44fd44..e8ca262830 100644 --- a/charts/kubedbcom-hazelcast-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-hazelcast-editor-options/ui/create-ui.yaml @@ -1,316 +1,306 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Hazelcast/versions - if: isToggleOn|databases/Hazelcast/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Hazelcast/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Hazelcast/versions + if: + type: function + name: isToggleOn|databases/Hazelcast/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Hazelcast/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Hazelcast/mode + loader: getAdminOptions|databases/Hazelcast/mode + if: + type: function + name: isToggleOn|databases/Hazelcast/mode + label: Database mode + isHorizontal: true + watcher: + func: toggleTls + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + label: Replicaset number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/Hazelcast/mode - fetch: getAdminOptions|databases/Hazelcast/mode - hasDescription: true - if: isToggleOn|databases/Hazelcast/mode - label: - text: labels.database.mode - onChange: toggleTls - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: isEqualToModelPathValue|Replicaset|/spec/mode - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine_profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - loader: getSecrets + label: License Secret + refresh: true + schema: schema/properties/spec/properties/licenseSecret/properties/name + type: select + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - fetch: getSecrets - label: - text: labels.licenseSecret - refresh: true - schema: - $ref: schema#/properties/spec/properties/licenseSecret/properties/name + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default type: select - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - init: + type: func + value: setBackup + if: + type: function + name: returnFalse + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - disable: showArchiverAlert + label: Enable Archiver? + watcher: + func: onArchiverChange + paths: + - schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default + schema: schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - if: + type: function + name: showArchiverAlert + label: The selected StorageClass does not support Archiver + type: warning + if: + type: function + name: returnFalse + type: block-layout + - elements: + - init: + type: func + value: checkHostnameOrIP + if: + type: function + name: isToggleOn|tls + label: Enable TLS? + watcher: + func: checkHostnameOrIP + paths: + - schema/properties/spec/properties/admin/properties/tls/properties/default + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - computed: setBackup - if: returnFalse - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + type: block-layout + - elements: + - init: + type: func + value: checkHostnameOrIP + if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + watcher: + func: checkHostnameOrIP + paths: + - schema/properties/spec/properties/admin/properties/expose/properties/default + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - disabled: showArchiverAlert - label: - text: Enable Archiver? - onChange: onArchiverChange - schema: - $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default - type: switch - - alertInfo: - show: true - type: neutral - if: showArchiverAlert - label: - text: The selected StorageClass does not support Archiver - type: label-element - if: returnFalse - type: single-step-form - - elements: - - computed: checkHostnameOrIP - if: isToggleOn|tls - label: - text: Enable TLS? - onChange: checkHostnameOrIP - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - elements: - - computed: checkHostnameOrIP - if: isToggleOn|expose - label: - text: Expose via Gateway? - onChange: checkHostnameOrIP - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-hazelcast-editor-options/ui/functions.js b/charts/kubedbcom-hazelcast-editor-options/ui/functions.js index 8e6b1a35a3..9f7ee47dda 100644 --- a/charts/kubedbcom-hazelcast-editor-options/ui/functions.js +++ b/charts/kubedbcom-hazelcast-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1182 +317,1204 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + function showAuthSecretField() { + return !showAuthPasswordField() + } - const resources = (resp && resp.data && resp.data.items) || [] + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -async function getMySqlVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resources = (resp && resp.data && resp.data.items) || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + async function getMySqlVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, + }, + } - const resources = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - // keep only non deprecated versions - const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const resources = (resp && resp.data && resp.data.items) || [] - filteredMySqlVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMySqlVersions -} + // keep only non deprecated versions + const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + filteredMySqlVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMySqlVersions } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } + } - if (owner && cluster && namespace) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + if (owner && cluster && namespace) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { + items: { + data: { username: null, password: null }, + metadata: { name: null }, + type: null, + }, }, }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) - }) + const filteredSecrets = secrets.filter((item) => { + const validType = [ + 'kubernetes.io/service-account-token', + 'Opaque', + 'kubernetes.io/basic-auth', + ] + return validType.includes(item.type) + }) - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + } } + return [] } - return [] -} -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function updateAgentValue(val) { + commit('wizard/model$update', { + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', + force: true, + }) + + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', + force: true, + }) } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + function setReplicaNumber() { + const modelPathValue = getValue(model, '/spec/mode') + if (modelPathValue === 'Topology') { + return 2 + } else return 1 + } -function setReplicaNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 2 - } else return 1 -} -function setRouterNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 3 - } else return 1 -} + function setRouterNumber() { + const modelPathValue = getValue(model, '/spec/mode') + if (modelPathValue === 'Topology') { + return 3 + } else return 1 + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + if (val === 'capz' && ifDedicated()) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} - -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Hazelcast/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Hazelcast/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Hazelcast/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') } - if (!features.includes('tls')) { + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - if (!features.includes('binding')) { + + function clearArbiterHidden() { commit('wizard/model$update', { - path: '/spec/admin/expose/default', + path: `/spec/arbiter/enabled`, value: false, force: true, }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { + commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', + path: `/spec/hidden/enabled`, value: false, force: true, }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let hostName = '' + let ip = '' + + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const gatewayinfosurl = `/clusters/${owner}/${cluster}/proxy/meta.k8s.appscode.com/v1alpha1/gatewayinfos/${namespace}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + const gatewayinfosResp = await axios.get(gatewayinfosurl) + hostName = gatewayinfosResp.data?.spec?.hostName + ip = gatewayinfosResp.data?.spec?.ip + } catch (e) { + console.log(e) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} -let archiverMap = [] -let archiverCalled = false + if (!getValue(model, `/spec/admin/databases/Hazelcast/mode/toggle`)) { + let defMode = getDefault('databases/Hazelcast/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Hazelcast/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } -function getAdminOptions({ getValue, axios, model, watchDependency, storeGet, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (type === 'storageClasses' && !archiverCalled) { - getArchiverName({ axios, storeGet }) + setDiscriminatorValue('/bundleApiLoaded', true) } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + return returnArray } - const backupVal = getValue(model, '/spec/backup/tool') - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + let archiverMap = [] + let archiverCalled = false + + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') + + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName() + } + + const options = getValue(model, `/spec/admin/${type}/available`) || [] + + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } + + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function returnFalse() { + return false + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') } -} -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = [] + return !validType.includes(modelPathValue) + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} - -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory - } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue - } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') } } - if (resource === 'memory') { + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } + + function onAuthChange() { commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: '/spec/authSecret/name', + value: '', force: true, }) commit('wizard/model$update', { - path: comparePath, - value: memory, + path: '/spec/authSecret/password', + value: '', force: true, }) - return memory - } else { + } + + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } + + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] + } + + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} -function toggleTls({ commit, model, getValue }) { - let modelPathValue = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: modelPathValue !== 'Standalone', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/admin/tls/toggle', - value: modelPathValue !== 'Standalone', - force: true, - }) -} - -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory + } else { + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu + } + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + commit('wizard/model$update', { + path: commitPath, + value: val, + force: true, + }) + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function toggleTls() { + let modelPathValue = getValue(model, '/spec/mode') + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: modelPathValue !== 'Standalone', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/admin/tls/toggle', + value: modelPathValue !== 'Standalone', + force: true, + }) } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showArchiverAlert({ watchDependency, model, getValue, commit }) { - watchDependency('model#/spec/admin/storageClasses/default') + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } - const mode = getValue(model, '/spec/mode') - if (mode === 'Standalone') return false + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } - const stClass = getValue(model, '/spec/admin/storageClasses/default') - const found = archiverMap.find((item) => item.storageClass === stClass) - const show = !found?.annotation + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } - // toggle archiver to false when storageClass annotation not found - if (show) + function onReferSecretChange() { commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, + path: '/spec/authSecret/name', + value: '', force: true, }) - else onArchiverChange({ model, getValue, commit }) + } - return show -} + function showArchiverAlert() { + // watchDependency('model#/spec/admin/storageClasses/default') -function showArchiver({ watchDependency, getValue, model, commit }) { - watchDependency('model#/spec/mode') - const dbmode = getValue(model, '/spec/mode') + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false - if (dbmode === 'Standalone') { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - 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, + }) + else onArchiverChange() + + return show } - return checkIfFeatureOn({ getValue, model }, 'archiver') -} -async function checkHostnameOrIP({ commit, model, getValue }) { - const tls = getValue(model, '/spec/admin/tls/default') - const expose = getValue(model, '/spec/admin/expose/default') - if (tls && expose) { - if (hostName) { + function showArchiver() { + // watchDependency('model#/spec/mode') + const dbmode = getValue(model, '/spec/mode') + + if (dbmode === 'Standalone') { commit('wizard/model$update', { - path: '/spec/hostName', - value: hostName, + path: '/spec/admin/archiver/enable/default', + value: false, force: true, }) + return false + } + return checkIfFeatureOn('archiver') + } + + function checkHostnameOrIP() { + const tls = getValue(model, '/spec/admin/tls/default') + const expose = getValue(model, '/spec/admin/expose/default') + if (tls && expose) { + if (hostName) { + commit('wizard/model$update', { + path: '/spec/hostName', + value: hostName, + force: true, + }) + } else { + commit('wizard/model$update', { + path: '/spec/ip', + value: ip, + force: true, + }) + } } else { + commit('wizard/model$update', { + path: '/spec/hostName', + value: '', + force: true, + }) commit('wizard/model$update', { path: '/spec/ip', - value: ip, + value: '', force: true, }) } - } else { - commit('wizard/model$update', { - path: '/spec/hostName', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/ip', - value: '', - force: true, - }) } -} -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) + function onArchiverChange() { + 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, - }) - else - commit('wizard/model$update', { - path: '/spec/archiverName', - value: '', - force: true, - }) -} + if (isArchiverOn && found?.annotation) + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) + else + commit('wizard/model$update', { + path: '/spec/archiverName', + value: '', + force: true, + }) + } -async function getArchiverName({ axios, storeGet }) { - 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) + async function getArchiverName() { + 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) + } } -} -return { - getArchiverName, - onArchiverChange, - checkHostnameOrIP, - showArchiver, - showArchiverAlert, - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - setLimits, - setRequests, - toggleTls, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - returnFalse, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - showStorageSizeField, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - getResources, - getMySqlVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - setReplicaNumber, - setRouterNumber, - setBackup, - showAdditionalSettings, - getDefault, + return { + getArchiverName, + onArchiverChange, + checkHostnameOrIP, + showArchiver, + showArchiverAlert, + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + initBundle, + returnFalse, + setLimits, + setRequests, + toggleTls, + getNamespaces, + updateAlertValue, + getAdminOptions, + isToggleOn, + showAlerts, + getNodeTopology, + clearArbiterHidden, + showHidden, + isConfigDatabaseOn, + notEqualToDatabaseMode, + filterNodeTopology, + onAuthChange, + setMonitoring, + isMachineNotCustom, + isMachineCustom, + showIssuer, + showArbiter, + clearConfiguration, + showStorageSizeField, + onBackupSwitch, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + showAuthSecretField, + getResources, + getMySqlVersions, + onCreateAuthSecretChange, + getSecrets, + getMachineListForOptions, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + setReplicaNumber, + setRouterNumber, + setBackup, + showAdditionalSettings, + getDefault, + } } diff --git a/charts/kubedbcom-ignite-editor-options/ui/create-ui.yaml b/charts/kubedbcom-ignite-editor-options/ui/create-ui.yaml index 5c0335f79f..c7c679f84a 100644 --- a/charts/kubedbcom-ignite-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-ignite-editor-options/ui/create-ui.yaml @@ -1,243 +1,222 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Ignite/versions - if: isToggleOn|databases/Ignite/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Ignite/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Ignite/versions + if: + type: function + name: isToggleOn|databases/Ignite/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Ignite/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Ignite/mode + loader: getAdminOptions|databases/Ignite/mode + if: + type: function + name: isToggleOn|databases/Ignite/mode + label: Database mode + isHorizontal: true + watcher: + func: toggleTls + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + label: Replicaset number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/Ignite/mode - fetch: getAdminOptions|databases/Ignite/mode - hasDescription: true - if: isToggleOn|databases/Ignite/mode - label: - text: labels.database.mode - onChange: toggleTls - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: isEqualToModelPathValue|Replicaset|/spec/mode - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine_profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - type: single-step-form + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-ignite-editor-options/ui/functions.js b/charts/kubedbcom-ignite-editor-options/ui/functions.js index 26d7b776bd..397af71ca7 100644 --- a/charts/kubedbcom-ignite-editor-options/ui/functions.js +++ b/charts/kubedbcom-ignite-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1063 +317,1084 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + function showAuthSecretField() { + return !showAuthPasswordField() + } - const resources = (resp && resp.data && resp.data.items) || [] + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -async function getMySqlVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resources = (resp && resp.data && resp.data.items) || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + async function getMySqlVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resources = (resp && resp.data && resp.data.items) || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, + }, + } - // keep only non deprecated versions - const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - filteredMySqlVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMySqlVersions -} + const resources = (resp && resp.data && resp.data.items) || [] -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + // keep only non deprecated versions + const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + + filteredMySqlVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMySqlVersions } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } + } - if (owner && cluster && namespace) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + if (owner && cluster && namespace) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { + items: { + data: { username: null, password: null }, + metadata: { name: null }, + type: null, + }, }, }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) - }) + const filteredSecrets = secrets.filter((item) => { + const validType = [ + 'kubernetes.io/service-account-token', + 'Opaque', + 'kubernetes.io/basic-auth', + ] + return validType.includes(item.type) + }) - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + } } + return [] } - return [] -} -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function updateAgentValue(val) { + commit('wizard/model$update', { + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', + force: true, + }) + + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', + force: true, + }) } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + function setReplicaNumber() { + const modelPathValue = getValue(model, '/spec/mode') + if (modelPathValue === 'Topology') { + return 2 + } else return 1 + } -function setReplicaNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 2 - } else return 1 -} -function setRouterNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 3 - } else return 1 -} + function setRouterNumber() { + const modelPathValue = getValue(model, '/spec/mode') + if (modelPathValue === 'Topology') { + return 3 + } else return 1 + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + if (val === 'capz' && ifDedicated()) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} - -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Ignite/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Ignite/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Ignite/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') } - if (!features.includes('tls')) { + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - if (!features.includes('binding')) { + + function clearArbiterHidden() { commit('wizard/model$update', { - path: '/spec/admin/expose/default', + path: `/spec/arbiter/enabled`, value: false, force: true, }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { + commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', + path: `/spec/hidden/enabled`, value: false, force: true, }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} - -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let namespaces = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - return returnArray -} - -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!getValue(model, `/spec/admin/databases/Ignite/mode/toggle`)) { + let defMode = getDefault('databases/Ignite/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Ignite/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + namespaces = getNamespaces() + setDiscriminatorValue('/bundleApiLoaded', true) } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + function fetchNamespaces() { + // watchDependency('discriminator#/bundleApiLoaded') + return namespaces } - const backupVal = getValue(model, '/spec/backup/tool') - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode } -} -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = [] + return !validType.includes(modelPathValue) + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') + + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') } - } catch (e) { - console.log(e) } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory - } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue - } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } + + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + const projects = resp?.data?.status?.projects + if (projects) { + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } + return [] } - if (resource === 'memory') { + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } + + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } + } + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory + } else { + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu + } + } + + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: comparePath, - value: memory, + path: commitPath, + value: val, force: true, }) - return memory - } else { + } + + function toggleTls() { + let modelPathValue = getValue(model, '/spec/mode') commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/admin/tls/default', + value: modelPathValue !== 'Standalone', force: true, }) commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/tls/toggle', + value: modelPathValue !== 'Standalone', force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function toggleTls({ commit, model, getValue }) { - let modelPathValue = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: modelPathValue !== 'Standalone', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/admin/tls/toggle', - value: modelPathValue !== 'Standalone', - force: true, - }) -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() } - return options -} - -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - setLimits, - setRequests, - toggleTls, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - returnFalse, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - showStorageSizeField, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - getResources, - getMySqlVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - setReplicaNumber, - setRouterNumber, - setBackup, - showAdditionalSettings, - getDefault, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + initBundle, + returnFalse, + setLimits, + setRequests, + toggleTls, + getNamespaces, + updateAlertValue, + getAdminOptions, + isToggleOn, + showAlerts, + getNodeTopology, + clearArbiterHidden, + showHidden, + isConfigDatabaseOn, + notEqualToDatabaseMode, + filterNodeTopology, + onAuthChange, + setMonitoring, + isMachineNotCustom, + isMachineCustom, + showIssuer, + showArbiter, + clearConfiguration, + showStorageSizeField, + onBackupSwitch, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + showAuthSecretField, + getResources, + getMySqlVersions, + onCreateAuthSecretChange, + getSecrets, + getMachineListForOptions, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + setReplicaNumber, + setRouterNumber, + setBackup, + showAdditionalSettings, + getDefault, + fetchNamespaces, + } } diff --git a/charts/kubedbcom-kafka-editor-options/ui/create-ui.yaml b/charts/kubedbcom-kafka-editor-options/ui/create-ui.yaml index 150979e7ee..8de6ed215a 100644 --- a/charts/kubedbcom-kafka-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-kafka-editor-options/ui/create-ui.yaml @@ -1,413 +1,384 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Kafka/versions - if: isToggleOn|databases/Kafka/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Kafka/properties/versions/properties/default - type: select - - computed: getDefault|databases/Kafka/mode - fetch: getAdminOptions|databases/Kafka/mode - hasDescription: true - if: isToggleOn|databases/Kafka/mode - label: - text: labels.database.mode - schema: - $ref: schema#/properties/spec/properties/mode - type: radio +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Kafka/versions + if: + type: function + name: isToggleOn|databases/Kafka/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Kafka/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Kafka/mode + loader: getAdminOptions|databases/Kafka/mode + if: + type: function + name: isToggleOn|databases/Kafka/mode + label: Database mode + isHorizontal: true + schema: schema/properties/spec/properties/mode + type: radio + - elements: + - label: Replicaset number + schema: schema/properties/spec/properties/replicas + type: input + if: + type: function + name: isEqualToModelPathValue|Combined|/spec/mode + type: block-layout + - elements: - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - label: Controller nodes + type: label-element + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/controller/properties/replicas type: input - if: isEqualToModelPathValue|Combined|/spec/mode - type: single-step-form - - elements: - elements: - - label: - text: labels.controller_nodes - type: label-element - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/controller/properties/replicas + - label: Storage size + schema: schema/properties/spec/properties/topology/properties/controller/properties/persistence/properties/size type: input - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/controller/properties/persistence/properties/size - type: input - schema: - $ref: schema#/properties/spec/properties/topology/properties/controller/properties/persistence - type: single-step-form - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/controller/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/controller - disabled: isMachineNotCustom|topology/controller - if: isMachineCustom|topology/controller - label: - text: labels.cpu - onChange: setRequests|cpu|topology/controller - schema: - $ref: schema#/properties/spec/properties/topology/properties/controller/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/controller - disabled: isMachineNotCustom|topology/controller - if: isMachineCustom|topology/controller - label: - text: labels.memory - onChange: setRequests|memory|topology/controller - schema: - $ref: schema#/properties/spec/properties/topology/properties/controller/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/spec/properties/topology/properties/controller - type: single-step-form + type: block-layout - elements: - - label: - text: labels.broker_nodes - type: label-element - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/broker/properties/replicas + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/controller/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/controller + if: + type: function + name: isMachineCustom|topology/controller + label: cpu + watcher: + func: setRequests|cpu|topology/controller + paths: + - schema/properties/spec/properties/topology/properties/controller/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/controller/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/controller + if: + type: function + name: isMachineCustom|topology/controller + label: memory + watcher: + func: setRequests|memory|topology/controller + paths: + - schema/properties/spec/properties/topology/properties/controller/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/controller/properties/podResources/properties/resources/properties/requests/properties/memory type: input - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/broker/properties/persistence/properties/size - type: input - schema: - $ref: schema#/properties/spec/properties/topology/properties/broker/properties/persistence - type: single-step-form - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/broker/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/broker - disabled: isMachineNotCustom|topology/broker - if: isMachineCustom|topology/broker - label: - text: labels.cpu - onChange: setRequests|cpu|topology/broker - schema: - $ref: schema#/properties/spec/properties/topology/properties/broker/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/broker - disabled: isMachineNotCustom|topology/broker - if: isMachineCustom|topology/broker - label: - text: labels.memory - onChange: setRequests|memory|topology/broker - schema: - $ref: schema#/properties/spec/properties/topology/properties/broker/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/spec/properties/topology/properties/broker - type: single-step-form - if: isEqualToModelPathValue|Topology|/spec/mode - schema: - $ref: schema#/properties/spec/properties/topology - type: single-step-form + label: Machine_profile + showLabels: true + type: block-layout + type: block-layout - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + - label: Broker nodes + type: label-element + - label: Replicaset number + schema: schema/properties/spec/properties/topology/properties/broker/properties/replicas type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - if: notEqualToDatabaseMode|Topology - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - elements: + - label: Storage size + schema: schema/properties/spec/properties/topology/properties/broker/properties/persistence/properties/size + type: input + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/broker/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/broker + if: + type: function + name: isMachineCustom|topology/broker + label: cpu + watcher: + func: setRequests|cpu|topology/broker + paths: + - schema/properties/spec/properties/topology/properties/broker/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/broker/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/broker + if: + type: function + name: isMachineCustom|topology/broker + label: memory + watcher: + func: setRequests|memory|topology/broker + paths: + - schema/properties/spec/properties/topology/properties/broker/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/broker/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine_profile + showLabels: true + type: block-layout + type: block-layout + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - if: isEqualToModelPathValue|Combined|/spec/mode - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: notEqualToDatabaseMode|Topology + label: Machine_profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: isEqualToModelPathValue|Combined|/spec/mode + label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring + type: switch + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|tls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + type: block-layout + - elements: + - label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - elements: - - if: isToggleOn|tls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - elements: - - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - if: isToggleOn|expose - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|expose + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-kafka-editor-options/ui/functions.js b/charts/kubedbcom-kafka-editor-options/ui/functions.js index 33e520182b..6f26b4556a 100644 --- a/charts/kubedbcom-kafka-editor-options/ui/functions.js +++ b/charts/kubedbcom-kafka-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,727 +317,743 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(modelPathValue) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Standalone', 'Replicaset'] + return validType.includes(modelPathValue) + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) - commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, - force: true, - }) - commit('wizard/model$update', { - path: comparePath, - value: cpu, - force: true, - }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' + + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] } else { - return resp.data?.status?.namespaces || [] + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] } - } catch (e) { - console.log(e) - } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Kafka/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Kafka/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Kafka/mode/available') || [] - if (arr.length) defMode = arr[0] + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + return [] } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) - } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) - } - - setDiscriminatorValue('/bundleApiLoaded', true) -} -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!getValue(model, `/spec/admin/databases/Kafka/mode/toggle`)) { + let defMode = getDefault('databases/Kafka/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Kafka/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + setDiscriminatorValue('/bundleApiLoaded', true) } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } -} - -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - showAdditionalSettings, - initBundle, - returnFalse, - isVariantAvailable, - showAuthPasswordField, - isEqualToModelPathValue, - showStorageSizeField, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - getCreateNameSpaceUrl, - setStorageClass, - getNamespaces, - isToggleOn, - getAdminOptions, - getNodeTopology, - filterNodeTopology, - isMachineNotCustom, - isMachineCustom, - notEqualToDatabaseMode, - onAuthChange, - clearConfiguration, - isConfigDatabaseOn, - showIssuer, - setMonitoring, - updateAlertValue, - showAlerts, - onBackupSwitch, - setBackup, - getDefault, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + showAdditionalSettings, + initBundle, + returnFalse, + isVariantAvailable, + showAuthPasswordField, + isEqualToModelPathValue, + showStorageSizeField, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + getCreateNameSpaceUrl, + setStorageClass, + getNamespaces, + isToggleOn, + getAdminOptions, + getNodeTopology, + filterNodeTopology, + isMachineNotCustom, + isMachineCustom, + notEqualToDatabaseMode, + onAuthChange, + clearConfiguration, + isConfigDatabaseOn, + showIssuer, + setMonitoring, + updateAlertValue, + showAlerts, + onBackupSwitch, + setBackup, + getDefault, + } } diff --git a/charts/kubedbcom-kafka-editor/ui/edit-ui.yaml b/charts/kubedbcom-kafka-editor/ui/edit-ui.yaml index 7c033acce9..6d395287db 100644 --- a/charts/kubedbcom-kafka-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-kafka-editor/ui/edit-ui.yaml @@ -1,1311 +1,884 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - fetch: getResources|core|v1|namespaces - label: - text: labels.namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - disableUnselect: true - disabled: true - fetch: getKafkaVersions|catalog.kubedb.com|v1alpha1|kafkaversions - label: - text: labels.database.version - onChange: onVersionChange - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/version - type: select - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/deletionPolicy - type: radio - - disabled: true - label: - text: labels.disable_security_question - onChange: onDisableSecurityChange - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/disableSecurity - type: switch - - elements: - - label: - text: labels.database.admin_secret - type: label-element - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/authSecret/properties/name - type: input - if: isSecurityEnabled - type: single-step-form - type: single-step-form - id: basic - title: steps.0.label -- form: - discriminator: - activeDatabaseMode: - type: string +type: multi-step-form +step: + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - label: - text: labels.to_update_disabled_section - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/kafkaopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations - - computed: setDatabaseMode - disabled: true - hasDescription: true - label: - text: labels.database.mode - onChange: deleteDatabaseModePath - options: - - description: options.database.mode.Combined.description - text: options.database.mode.Combined.label - value: Combined - - description: options.database.mode.Dedicated.description - text: options.database.mode.Dedicated.label - value: Dedicated - schema: - $ref: discriminator#/activeDatabaseMode - type: radio - - elements: - - disabled: true - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/replicas - type: input - - disabled: true - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/storage/properties/resources/properties/requests/properties/storage - type: input - - disabled: true - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/storage/properties/storageClassName - type: input - if: isEqualToDatabaseMode|Combined - type: single-step-form - - element: + - type: block-layout + if: + type: function + name: isConsole elements: - - disabled: true - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn/properties/replicas - type: input - - disabled: true - elements: - - elements: - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn/properties/storage/properties/resources/properties/requests/properties/storage - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn/properties/storage/properties/resources/properties/requests - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn/properties/storage/properties/resources - type: single-step-form - - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn/properties/storage/properties/storageClassName - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn/properties/storage - type: single-step-form - - disabled: true - label: - text: labels.suffix - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn/properties/suffix - type: input - - disabled: true - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn/properties/resources - type: resource-input-form - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology/properties/$dyn - show_label: true - type: single-step-form - if: isEqualToDatabaseMode|Dedicated - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology - type: array-input-form - type: single-step-form - id: topology - title: steps.1.label -- form: - elements: - - if: showTlsRecommendation - label: - text: labels.tls_recommended_text - type: label-element - - label: - text: labels.to_update_tls - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/kafkaopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=ReconfigureTLS - - disabled: true - label: - text: labels.enable_tls - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/enableSSL - type: switch - - disabled: true - elements: - - elements: - - computed: setApiGroupEdit - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: returnFalse - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - required: returnFalse - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - if: isSecurityEnabled - title: steps.2.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComKafka/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComKafka/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComKafka/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComKafka/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.3.label -- form: - elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.4.label -- form: - elements: - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - topology: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/topology - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComKafka/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - id: pod-template - title: steps.5.label -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array - elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/compute/broker/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-broker-max: - type: string - allowedMachine-broker-min: - type: string + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines + elements: + # topology mode - broker and controller + - type: block-layout + label: Topology + if: + type: function + name: dbTypeEqualsTo|topology + showLabels: false + # schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute elements: - - computed: setAllowedMachine|broker|min - disableUnselect: true - fetch: getMachines|broker|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|broker - schema: - $ref: discriminator#/properties/allowedMachine-broker-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|broker|max - disableUnselect: true - fetch: getMachines|broker|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|broker - schema: - $ref: discriminator#/properties/allowedMachine-broker-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|broker - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/controlledResources - type: multiselect - label: - text: Broker - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/compute/controller/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-controller-max: - type: string - allowedMachine-controller-min: - type: string + # Broker section + - type: block-layout + label: Broker + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/compute/broker/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-broker-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|broker|min + loader: + name: getMachines|broker|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-broker-max + watcher: + func: onMachineChange|broker + paths: + - temp/properties/allowedMachine-broker-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-broker-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|broker|max + loader: + name: getMachines|broker|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-broker-min + watcher: + func: onMachineChange|broker + paths: + - temp/properties/allowedMachine-broker-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|broker + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker/properties/controlledResources + + # Controller section + - type: block-layout + label: Controller + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/compute/controller/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-controller-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|controller|min + loader: + name: getMachines|controller|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-controller-max + watcher: + func: onMachineChange|controller + paths: + - temp/properties/allowedMachine-controller-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-controller-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|controller|max + loader: + name: getMachines|controller|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-controller-min + watcher: + func: onMachineChange|controller + paths: + - temp/properties/allowedMachine-controller-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|controller + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/controlledResources + + # combined mode - node only + - type: block-layout + label: Combined + if: + type: function + name: dbTypeEqualsTo|combined + showLabels: false + # schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute elements: - - computed: setAllowedMachine|controller|min - disableUnselect: true - fetch: getMachines|controller|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|controller - schema: - $ref: discriminator#/properties/allowedMachine-controller-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/minAllowed/properties/cpu - type: input - - label: - text: Memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|controller|max - disableUnselect: true - fetch: getMachines|controller|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|controller - schema: - $ref: discriminator#/properties/allowedMachine-controller-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/maxAllowed/properties/cpu - type: input - - label: - text: Memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|controller - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller/properties/controlledResources - type: multiselect - label: - text: Controller - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller - show_label: true - type: single-step-form - if: dbTypeEqualsTo|topology - label: - text: Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/compute/node/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-node-max: - type: string - allowedMachine-node-min: - type: string + # Node section + - type: block-layout + label: Node + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/compute/node/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-node-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|node|min + loader: + name: getMachines|node|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-node-max + watcher: + func: onMachineChange|node + paths: + - temp/properties/allowedMachine-node-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-node-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|node|max + loader: + name: getMachines|node|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-node-min + watcher: + func: onMachineChange|node + paths: + - temp/properties/allowedMachine-node-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|node + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/nodeTopology elements: - - computed: setAllowedMachine|node|min - disableUnselect: true - fetch: getMachines|node|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|node - schema: - $ref: discriminator#/properties/allowedMachine-node-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/cpu - type: input - - label: - text: Memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|node|max - disableUnselect: true - fetch: getMachines|node|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|node - schema: - $ref: discriminator#/properties/allowedMachine-node-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/cpu - type: input - - label: - text: Memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|node - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node/properties/controlledResources - type: multiselect - label: - text: Node - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node - show_label: true - type: single-step-form - if: dbTypeEqualsTo|combined - label: - text: Combined - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - computed: getDbDetails - if: returnFalse - type: input - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/storage/broker/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/broker/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/broker/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/upperBound - type: input - if: dbTypeEqualsTo|topology - label: - text: Broker - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/broker - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/storage/controller/trigger - label: - text: Trigger + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler + loader: getDbDetails + elements: + - type: block-layout + showLabels: false + elements: + - type: block-layout + showLabels: true + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/name + - type: select + label: SelectNamespace + loader: getNamespaces + hasGroup: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + refresh: true + validation: + type: required + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/databaseRef/properties/name + - type: radio + label: Select Type + validation: + type: required + isHorizontal: true + schema: discriminator/properties/autoscalingType options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/trigger - type: select - - label: - text: Expansion Mode + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + if: + type: function + name: isConsole + watcher: + func: initMetadata + paths: + - discriminator/properties/autoscalingType + # Broker mode + - type: block-layout + label: Broker + showLabels: true + if: + type: function + name: dbTypeEqualsTo|topology + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/storage/broker/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComKafka/spec/topology/broker/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/broker/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/broker/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/broker/properties/upperBound + # Controller mode + - type: block-layout + label: Controller + showLabels: true + if: + type: function + name: dbTypeEqualsTo|topology + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/storage/controller/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComKafka/spec/topology/controller/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/controller/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/controller/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/upperBound + # Node mode + - type: block-layout + label: Node + showLabels: true + if: + type: function + name: dbTypeEqualsTo|combined + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/storage/node/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/expansionMode + - type: threshold-input + label: Usage Threshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComKafka/spec/topology/node/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/node/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/node/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound + # Ops Request Options + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring + elements: + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComKafka/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection + elements: + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComKafka/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComKafka/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/controller/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/controller/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/controller/properties/upperBound - type: input - if: dbTypeEqualsTo|topology - label: - text: Controller - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/controller - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComKafkaAutoscaler/spec/storage/node/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/expansionMode - type: select - - label: - text: Usage Threshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: Scaling Rules - onChange: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/node/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComKafkaAutoscaler/spec/storage/node/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound - type: input - if: dbTypeEqualsTo|combined - label: - text: Node - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/compute/properties/node - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComKafkaAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.7.label -- form: - discriminator: - binding: - default: false - type: boolean + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComKafka/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: + type: input + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComKafka/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: binding + label: Gateway Binding elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -type: multi-step-form + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-kafka-editor/ui/functions.js b/charts/kubedbcom-kafka-editor/ui/functions.js index ec52e22474..bff182a19d 100644 --- a/charts/kubedbcom-kafka-editor/ui/functions.js +++ b/charts/kubedbcom-kafka-editor/ui/functions.js @@ -1,1585 +1,959 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx, setDiscriminatorValue }, discriminatorPath) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - if (discriminatorPath) { - setDiscriminatorValue(discriminatorPath, { - ui: ui.data || {}, - language: language.data || {}, - functions, - }) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + /********** Initialize Discriminator **************/ -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + setDiscriminatorValue('binding', true) + setDiscriminatorValue('hidePreviewFromWizard', undefined) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') - const resources = (resp && resp.data && resp.data.items) || [] + let autoscaleType = '' + let dbDetails = {} - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + function isKubedb() { + return !!storeGet('/route/params/actions') } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + function isConsole() { + const isKube = isKubedb() -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + return !isKube + } + + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/kafkas/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComKafkaAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) } - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + // delete the other type object from model + if (type === 'compute') + commit('wizard/model$delete', '/resources/autoscalingKubedbComKafkaAutoscaler/spec/storage') + if (type === 'storage') + commit('wizard/model$delete', '/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute') + } + + async function fetchTopologyMachines() { + const instance = hasAnnotations() + + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) + + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + function dbTypeEqualsTo(type) { + // watchDependency('discriminator#/dbDetails') - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const { spec } = dbDetails || {} + const { topology } = spec || {} + let verd = '' + if (topology) verd = 'topology' + else { + verd = 'combined' + } + clearSpecModel(verd) + return type === verd && spec } - return ans -} + function clearSpecModel(dbtype) { + if (dbtype === 'standalone') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/cluster`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/sentinel`, + ) + } else if (dbtype === 'cluster') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/standalone`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/sentinel`, + ) + } else if (dbtype === 'sentinel') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/standalone`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/cluster`, + ) + } + } -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + return !!instance } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + function setAllowedMachine(type, minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} } - }) -} - -function returnTrue() { - return true -} -function returnStringYes() { - return 'yes' -} + const machine = parsedInstance[type] || '' + const mx = machine?.includes(',') ? machine.split(',')[1] : '' + const mn = machine?.includes(',') ? machine.split(',')[0] : '' -function isDedicatedModeSelected({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComKafka/spec/topology') - isDedicatedSelected = getValue(model, '/resources/kubedbComKafka/spec/topology') + if (minmax === 'min') return mn + else return mx + } - return !!isDedicatedSelected -} + async function getMachines(type, minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${type}-${depends}` -function isCombinedModeSelected({ model, getValue, watchDependency }) { - return !isDedicatedSelected({ model, getValue, watchDependency }) -} + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) -function isDiscriminatorEqualTo( - { discriminator, getValue, watchDependency }, - discriminatorPath, - value, -) { - watchDependency('discriminator#' + discriminatorPath) - const pathValue = getValue(discriminator, discriminatorPath) + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - return value === pathValue -} + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) -// ************************* Basic Info ********************************************** + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) -async function getKafkaVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, authPlugin: null }, - }, - }, + return dependantIndex === -1 ? machines : filteredMachine } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } - // keep only non deprecated versions - const filteredKafkaVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) + const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) + const minMaxMachine = `${minMachine},${maxMachine}` - filteredKafkaVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredKafkaVersions -} + parsedInstance[type] = minMaxMachine + const instanceString = JSON.stringify(parsedInstance) + annotations['kubernetes.io/instance-type'] = instanceString -function isSecurityEnabled({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComKafka/spec/disableSecurity') - const value = getValue(model, '/resources/kubedbComKafka/spec/disableSecurity') - return !value -} + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute/${type}` -function onDisableSecurityChange({ model, getValue, commit }) { - const disableSecurity = getValue(model, '/resources/kubedbComKafka/spec/disableSecurity') + if (minMachine && maxMachine && instance !== instanceString) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: annotations, + force: true, + }) + } + } - if (disableSecurity) { - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/authSecret') - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/tls') + function hasNoAnnotations() { + return !hasAnnotations() } -} -function onEnableSSLChange({ model, getValue, commit }) { - const enabelSSL = getValue(model, '/resources/kubedbComKafka/spec/enableSSL') + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, + }) + return list + } - if (enabelSSL === false) { - removeCertificatesOfAliases({ model, getValue, commit }, ['server', 'client']) + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') && + !!getValue(discriminator, '/autoscalingType') + ) } -} -function removeCertificatesOfAliases({ model, getValue, commit }, aliasesToRemove) { - const certificates = getValue(model, '/resources/kubedbComKafka/spec/tls/certificates') || [] - const updatedCertificates = certificates.filter((item) => !aliasesToRemove.includes(item.alias)) - commit('wizard/model$update', { - path: '/resources/kubedbComKafka/spec/tls/certificates', - value: updatedCertificates, - force: true, - }) -} + function setApplyToIfReady() { + return 'IfReady' + } -/************************************* Database Secret Section ********************************************/ + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComKafka/spec/authSecret') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return !authSecret -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') + const resources = (resp && resp.data && resp.data.items) || [] - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_admin_cred/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') + const resources = (resp && resp.data && resp.data.items) || [] - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_admin_cred/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_admin_cred/data/username', - value: encodePassword({}, 'admin'), - force: true, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) - } else { - commit('wizard/model$delete', '/resources/secret_admin_cred') } -} -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] + } -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_admin_cred') + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + params: { filter: { items: { metadata: { name: null } } } }, }, ) - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + const resources = (resp && resp.data && resp.data.items) || [] - filteredSecrets.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + return { + text: name, + value: name, + } }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] } -} - -function showSecretSection({ model, getValue, watchDependency, storeGet }) { - const steps = storeGet('/wizard/configureOptions') - - return ( - !steps.includes('internal-users') && isSecurityEnabled({ model, getValue, watchDependency }) - ) -} - -// ********************* Database Mode *********************** -function isNotCombinedMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Combined' -} -function setDatabaseMode({ model, getValue }) { - isDedicatedSelected = getValue(model, '/resources/kubedbComKafka/spec/topology') - if (isDedicatedSelected) { - return 'Dedicated' - } else { - return 'Combined' - } -} + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, setDiscriminatorValue, getValue, model }, - path, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - const resources = (resp && resp.data && resp.data.items) || [] + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - if (!path) { - setDiscriminatorValue('/storageClasses', resources) + return ans } - storageClassList = resources - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ model, getValue, commit }, path) - return resources -} - -function setStorageClass({ model, getValue, commit }, path) { - const deletionPolicy = getValue(model, '/resource/kubedbComKafka/spec/deletionPolicy') || '' - let storageClass = getValue(model, path) || '' - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + function removeCertificatesOfAliases(aliasesToRemove) { + const certificates = getValue(model, '/resources/kubedbComKafka/spec/tls/certificates') || [] + const updatedCertificates = certificates.filter((item) => !aliasesToRemove.includes(item.alias)) + commit('wizard/model$update', { + path: '/resources/kubedbComKafka/spec/tls/certificates', + value: updatedCertificates, + force: true, + }) + } - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + /************* Monitoring *************/ - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComKafka/spec/monitor', + value: {}, + force: true, + }) } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + commit('wizard/model$delete', '/resources/kubedbComKafka/spec/monitor') } - } - if (storageClass && path) { + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: path, - value: storageClass, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) } -} -function deleteDatabaseModePath({ discriminator, getValue, commit }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - if (mode === 'Dedicated') { - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/podTemplate') - } else if (mode === 'Combined') { - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/topology') + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue } -} -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComKafka/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } - return mode === value -} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComKafka/spec/metadata/labels') -function getStorageClassNamesFromDiscriminator( - { model, discriminator, getValue, watchDependency, commit }, - path, -) { - watchDependency('discriminator#/storageClasses') - const options = getValue(discriminator, '/storageClasses') || [] + const agent = getValue(model, '/resources/kubedbComKafka/spec/monitor/agent') - setStorageClass({ model, getValue, commit }, path) - return options -} + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) + } + } -// ************************** TLS ******************************************* + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComKafka/spec/monitor/agent') -function setApiGroup() { - return 'cert-manager.io' -} + if (!agent) { + removeCertificatesOfAliases(['metrics-exporter']) + } -function setApiGroupEdit({ model, getValue }) { - const kind = getValue(model, '/resources/kubedbComKafka/spec/tls/issuerRef/kind') - const name = getValue(model, '/resources/kubedbComKafka/spec/tls/issuerRef/name') - return kind && name ? 'cert-manager.io' : '' -} + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComKafka/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComKafka/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComKafka/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComKafka/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } } - try { - const resp = await axios.get(url) + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - const resources = (resp && resp.data && resp.data.items) || [] + const isKube = !!storeGet('/route/params/actions') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/kafkaopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name', + ) + } + } - return !resp -} + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComKafka/spec/clusterAuthMode') - return val || 'x509' -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComKafka/spec/sslMode') - return val || 'requireSSL' -} - -function showTlsConfigureSection({ watchDependency, model, getValue }) { - watchDependency('model#/resources/kubedbComKafka/spec/enableSSL') - const configureStatus = getValue(model, '/resources/kubedbComKafka/spec/enableSSL') - return configureStatus -} - -function onTlsConfigureChange({ model, getValue, commit }) { - const configureStatus = getValue(model, '/resources/kubedbComKafka/spec/enableSSL') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComKafka/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/tls') - } -} - -async function showTlsRecommendation({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/issuers` - - try { - await axios.get(url, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - return false - } catch (err) { - // if any error response status is 404 or not - if (err.response && err.response.status === 404) { - resp = false - } - console.log(err) - return true - } -} - -async function getAliasOptions({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComKafka/spec/enableSSL') - watchDependency('model#/resources/kubedbComKafka/spec/monitor') - - const enableSSL = getValue(model, '/resources/kubedbComKafka/spec/enableSSL') - - // always include transport cert alias - const aliases = [] - - if (enableSSL) { - aliases.push('server') - aliases.push('client') - } - - return aliases -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComKafka/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComKafka/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComKafka/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComKafka/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComKafka/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComKafka/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, + path: '/resources/kubedbComKafka/spec/monitor/prometheus/exporter', + value: {}, force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComKafka/spec/monitor/prometheus/exporter') } } - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' } } - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_user_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComKafka/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComKafka/spec/monitor/agent') - if (!agent) { - removeCertificatesOfAliases({ model, getValue, commit }, ['metrics-exporter']) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -//////////////////// service monitor /////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, + }) -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_user_config') - commit('wizard/model$delete', '/resources/config_secret') - } else { - const value = getValue(model, '/resources/secret_user_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_user_config', - value: {}, - force: true, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComKafka/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_user_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setConfigFiles({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/secret_user_config/stringData') - const configFiles = getValue(model, '/resources/secret_user_config/stringData') - - const files = [] - for (const item in configFiles) { - const obj = {} - obj.key = item - obj.value = configFiles[item] - files.push(obj) - } - - setDiscriminatorValue('/configFiles', files) - - return files -} - -function onConfigFilesChange({ discriminator, getValue, commit }) { - const files = getValue(discriminator, '/configFiles') - - const configFiles = {} - - if (files) { - files.forEach((item) => { - const { key, value } = item - configFiles[key] = value + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - commit('wizard/model$update', { - path: '/resources/secret_user_config/stringData', - value: configFiles, - force: true, - }) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_user_config') - } -} - -function initSetCustomConfig({ model, getValue }) { - const configSecret = getValue(model, '/resources/kubedbComKafka/spec/configSecret/name') - - if (configSecret) return 'yes' - else return 'no' -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/kafkaopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComKafka/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } -} + if (!configMapName) return [] -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} + const configMaps = (resp && resp.data && resp.data.data) || {} -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace', - value: namespace, - force: true, - }) + return configMapKeys + } catch (e) { + console.log(e) + return [] } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/kafkas/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) - } - } - - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComKafkaAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') + const secrets = (resp && resp.data && resp.data.items) || [] - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' - } - clearSpecModel({ commit }, verd) - return type === verd && spec -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComKafkaAutoscaler/spec/${autoscaleType}/cluster`, - ) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } } -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComKafkaAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute') -} -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name', + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComKafka/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', ) - } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComKafkaAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} - -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} + if (!secretName) return [] -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + const secret = (resp && resp.data && resp.data.data) || {} -function setApplyToIfReady() { - return 'IfReady' -} + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, - }) + return secretKeys + } catch (e) { + console.log(e) + return [] } } -} -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComKafkaBinding') - return isExposeBinding -} + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const 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 labels = getValue(model, '/resources/kubedbComKafka/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'KafkaBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComKafka/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'KafkaBinding', + metadata: { + labels, 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') + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComKafkaBinding', + value: bindingValues, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComKafkaBinding') + } } -} - -/****** Monitoring *********/ -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComKafka/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComKafka/spec/monitor/prometheus/exporter') + function returnFalse() { + return false } -} - -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) - - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } } } -} -function setAllowedMachine({ model, getValue }, type, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - const machine = parsedInstance[type] || '' - const mx = machine?.includes(',') ? machine.split(',')[1] : '' - const mn = machine?.includes(',') ? machine.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, type, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${type}-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }, type) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComKafkaAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value } - const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) - const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) - const minMaxMachine = `${minMachine},${maxMachine}` - - parsedInstance[type] = minMaxMachine - const instanceString = JSON.stringify(parsedInstance) - annotations['kubernetes.io/instance-type'] = instanceString - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComKafkaAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== instanceString) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + return { + isKubedb, + isConsole, + getDbDetails, + initMetadata, + fetchTopologyMachines, + dbTypeEqualsTo, + setTrigger, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + setControlledResources, + showOpsRequestOptions, + setApplyToIfReady, + getNamespaces, + fetchNodeTopology, + isNodeTopologySelected, + getDbs, + + handleUnit, + isRancherManaged, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onNamespaceChange, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + + isBindingAlreadyOn, + addOrRemoveBinding, + returnFalse, + + setValueFromDbDetails, } } - -return { - onCustomizeExporterChange, - showCustomizeExporterSection, - isRancherManaged, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - isDedicatedModeSelected, - isCombinedModeSelected, - isDiscriminatorEqualTo, - getKafkaVersions, - isSecurityEnabled, - onDisableSecurityChange, - onEnableSSLChange, - removeCertificatesOfAliases, - setDatabaseMode, - getStorageClassNames, - getStorageClassNamesFromDiscriminator, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - setApiGroupEdit, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - showTlsRecommendation, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - setAuthSecretPassword, - onAuthSecretPasswordChange, - showSecretSection, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - setConfigurationSource, - setConfigFiles, - onConfigFilesChange, - onSetCustomConfigChange, - initSetCustomConfig, - getOpsRequestUrl, - getCreateNameSpaceUrl, - setStorageClass, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, -} diff --git a/charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml b/charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml index 17b1b14132..f3bc18bb14 100644 --- a/charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml @@ -1,378 +1,350 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/MariaDB/versions + if: + type: function + name: isToggleOn|databases/MariaDB/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/MariaDB/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/MariaDB/mode + loader: getAdminOptions|databases/MariaDB/mode + if: + type: function + name: isToggleOn|databases/MariaDB/mode + label: Database mode + isHorizontal: true + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: EqualToDatabaseMode|Replicaset + label: Replicas + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine_profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/MariaDB/versions - if: isToggleOn|databases/MariaDB/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/MariaDB/properties/versions/properties/default + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - computed: getDefault|databases/MariaDB/mode - fetch: getAdminOptions|databases/MariaDB/mode - hasDescription: true - if: isToggleOn|databases/MariaDB/mode - label: - text: labels.database.mode - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: EqualToDatabaseMode|Replicaset - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/replicas + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - init: + type: func + value: getDefault|pointInTimeRecovery + if: + type: function + name: isToggleOn|pointInTimeRecovery + label: Point in-time Recovery? + schema: temp/recovery + type: switch - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + - label: Namespace + watcher: + func: setPointInTimeRecovery + paths: + - temp/refNamespace + validation: + type: required + schema: temp/refNamespace + type: input + - label: Name + watcher: + func: setPointInTimeRecovery + paths: + - temp/refDBName + validation: + type: required + schema: temp/refDBName type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + - customClass: mt-10 + label: Recovery Timestamp + schema: schema/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + if: + type: function + name: showRecovery + label: Point in-time Recovery + showLabels: true + type: block-layout + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size - type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - recovery: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options + options: + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - disable: showArchiverAlert + label: Enable Archiver? + watcher: + func: onArchiverChange + paths: + - schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default + schema: schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - computed: getDefault|pointInTimeRecovery - if: isToggleOn|pointInTimeRecovery - label: - text: Point in-time Recovery? - schema: - $ref: discriminator#/recovery + - if: + type: function + name: showArchiverAlert + label: The selected StorageClass does not support Archiver + type: warning + if: + type: function + name: showArchiver + type: block-layout + - elements: + - label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - discriminator: - refDBName: - type: string - refNamespace: - type: string - elements: - - label: - text: Namespace - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refNamespace - type: input - - label: - text: Name - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refDBName - type: input - - customClass: mt-10 - label: - text: Recovery Timestamp - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp - type: input - if: showRecovery - label: - text: Point in-time Recovery - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver - show_label: true - type: single-step-form - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - refresh: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/properties/backup + if: + type: function + name: isToggleOn|tls + type: block-layout + - elements: + - label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - disabled: showArchiverAlert - label: - text: Enable Archiver? - onChange: onArchiverChange - schema: - $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default - type: switch - - alertInfo: - show: true - type: neutral - if: showArchiverAlert - label: - text: The selected StorageClass does not support Archiver - type: label-element - if: showArchiver - type: single-step-form - - elements: - - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - if: isToggleOn|tls - type: single-step-form - - elements: - - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - if: isToggleOn|expose - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|expose + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-mariadb-editor-options/ui/functions.js b/charts/kubedbcom-mariadb-editor-options/ui/functions.js index 3d2f49511d..babd35604a 100644 --- a/charts/kubedbcom-mariadb-editor-options/ui/functions.js +++ b/charts/kubedbcom-mariadb-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1059 +317,1066 @@ const modeDetails = { }, } -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('recovery', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('refDBName', '') + setDiscriminatorValue('refNamespace', '') + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - const projects = resp?.data?.status?.projects - if (projects) { - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - namespaces = projectsNamespace - } else { - namespaces = resp?.data?.status?.namespaces || [] + ) + const projects = resp?.data?.status?.projects + if (projects) { + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + namespaces = projectsNamespace + } else { + namespaces = resp?.data?.status?.namespaces || [] + } + return namespaces + } catch (e) { + console.log(e) + return [] } - return namespaces - } catch (e) { - console.log(e) - return [] } -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function showRecovery({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/recovery') - const isRecoveryOn = getValue(discriminator, '/recovery') || '' - return isRecoveryOn -} + function showRecovery() { + // watchDependency('discriminator#/recovery') + const isRecoveryOn = getValue(discriminator, '/recovery') || '' + return isRecoveryOn + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -function showMonitoringSection({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/monitoringEnabledStatus') - return !!getValue(discriminator, '/monitoringEnabledStatus') -} + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') -function setMonitoringStatus({ model, getValue }) { - const status = getValue(model, '/spec/monitoring/agent') - return !!status -} + if (val === 'capz' && ifDedicated()) return true + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb]`, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] } - } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` - }) - url = url.slice(0, -1) - } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { + commit('wizard/model$update', { + path: '/spec/admin/storageClasses/default', + value: storageClass, + force: true, }) - return val - } catch (e) { - console.log(e) - return [] } } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + function EqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue === mode + } + + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + function returnFalse() { + return false } - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let namespaces = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } + commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -let namespaces = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!getValue(model, `/spec/admin/databases/MariaDB/mode/toggle`)) { + let defMode = getDefault('databases/MariaDB/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/MariaDB/mode/available') || [] + if (arr.length) defMode = arr[0] + } commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/mode', + value: defMode, force: true, }) } - } catch (e) { - console.log(e) - } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/MariaDB/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/MariaDB/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/MariaDB/mode/available') || [] - if (arr.length) defMode = arr[0] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } + namespaces = getNamespaces() + setDiscriminatorValue('/bundleApiLoaded', true) } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) - } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) + function fetchNamespaces() { + // watchDependency('discriminator#/bundleApiLoaded') + return namespaces } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + + async function getRecoveryNames(type) { + // watchDependency(`model#/spec/init/archiver/${type}/namespace`) + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` + if (type === 'encryptionSecret') + url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + const options = [] + if (namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + } + return options } - namespaces = getNamespaces({ axios, storeGet }) - setDiscriminatorValue('/bundleApiLoaded', true) -} -function fetchNamespaces({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return namespaces -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -async function getRecoveryNames({ getValue, model, watchDependency, storeGet, axios }, type) { - watchDependency(`model#/spec/init/archiver/${type}/namespace`) - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` - if (type === 'encryptionSecret') - url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - const options = [] - if (namespace) { - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, }) - } catch (e) { - console.log(e) } - } - return options -} -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + return returnArray } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` - commit('wizard/model$update', { - path: path, - value: returnArray[0], - force: true, - }) - } + let archiverMap = [] + let archiverCalled = false - return returnArray -} + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') -let archiverMap = [] -let archiverCalled = false + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName() + } -function getAdminOptions({ getValue, model, watchDependency, axios, storeGet, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + const options = getValue(model, `/spec/admin/${type}/available`) || [] - if (type === 'storageClasses' && !archiverCalled) { - getArchiverName({ axios, storeGet }) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } - const options = getValue(model, `/spec/admin/${type}/available`) || [] - - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + function showArchiver() { + return checkIfFeatureOn('archiver') } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} -function showArchiver({ getValue, model }) { - return checkIfFeatureOn({ getValue, model }, 'archiver') -} + async function getArchiverName() { + 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) -async function getArchiverName({ axios, storeGet }) { - 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) + 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') + function onArchiverChange() { + 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) - const via = getValue(model, '/spec/admin/archiver/via') + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const via = getValue(model, '/spec/admin/archiver/via') - if (!isArchiverOn) { - commit('wizard/model$update', { - path: '/spec/archiverName', - value: '', - force: true, - }) - } else { - if (via === 'VolumeSnapshotter') { + if (!isArchiverOn) { commit('wizard/model$update', { path: '/spec/archiverName', - value: found.annotation, + value: '', force: true, }) } else { - const kind = getValue(model, '/metadata/resource/kind') - commit('wizard/model$update', { - path: '/spec/archiverName', - value: kind.toLowerCase(), - force: true, - }) + if (via === 'VolumeSnapshotter') { + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) + } else { + const kind = getValue(model, '/metadata/resource/kind') + commit('wizard/model$update', { + path: '/spec/archiverName', + value: kind.toLowerCase(), + force: true, + }) + } } } -} -function showArchiverAlert({ watchDependency, model, getValue, commit }) { - watchDependency('model#/spec/admin/storageClasses/default') + function showArchiverAlert() { + // watchDependency('model#/spec/admin/storageClasses/default') - const mode = getValue(model, '/spec/mode') - if (mode === 'Standalone') return false + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false - const via = getValue(model, '/spec/admin/archiver/via') - - if (via === 'VolumeSnapshotter') { - // toggle archiver to false when storageClass annotation not found - const stClass = getValue(model, '/spec/admin/storageClasses/default') - const found = archiverMap.find((item) => item.storageClass === stClass) - const show = !found?.annotation - if (show) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - return true - } else onArchiverChange({ model, getValue, commit }) - } else onArchiverChange({ model, getValue, commit }) - return false -} + const via = getValue(model, '/spec/admin/archiver/via') -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && val + if (via === 'VolumeSnapshotter') { + // toggle archiver to false when storageClass annotation not found + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + if (show) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return true + } else onArchiverChange() + } else onArchiverChange() + return false } -} -function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const isAlertToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'alert', - ) - return isMonitorEnabled && isAlertToggleEnabled -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val } -} -function EqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue === mode -} -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function convertToLocal(input) { + const date = new Date(input) -function convertToLocal(input) { - const date = new Date(input) + if (isNaN(date.getTime())) { + return null + } - if (isNaN(date.getTime())) { - return null + return date.toString() } - return date.toString() -} - -function getComponentLogStats(snapshot) { - if (!snapshot || !snapshot.status || !snapshot.status.components) { - return null - } + function getComponentLogStats(snapshot) { + if (!snapshot || !snapshot.status || !snapshot.status.components) { + return null + } - const components = snapshot.status.components - const appKind = snapshot.spec?.appRef?.kind + const components = snapshot.status.components + const appKind = snapshot.spec?.appRef?.kind - if (appKind === 'MongoDB') { - for (const [key, value] of Object.entries(components)) { - if (key.endsWith('0') && value.logStats) { - return value.logStats + if (appKind === 'MongoDB') { + for (const [key, value] of Object.entries(components)) { + if (key.endsWith('0') && value.logStats) { + return value.logStats + } } } - } - if (components['wal'] && components['wal'].logStats) { - return components['wal'].logStats - } - - return null -} + if (components['wal'] && components['wal'].logStats) { + return components['wal'].logStats + } -async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const refNamespace = getValue(discriminator, '/refNamespace') - const refDBName = getValue(discriminator, '/refDBName') + return null + } - try { - const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` - const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` - const repositoriesResp = await axios.get(repositoriesUrl) - const snapshotsResp = await axios.get(snapshotsUrl) + async function setPointInTimeRecovery() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const refNamespace = getValue(discriminator, '/refNamespace') + const refDBName = getValue(discriminator, '/refDBName') - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/name`, - value: repositoriesResp.data?.spec.encryptionSecret.name, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/namespace`, - value: repositoriesResp.data?.spec.encryptionSecret.namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/name`, - value: `${refDBName}-full`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/name`, - value: `${refDBName}-manifest`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) + try { + const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` + const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` + const repositoriesResp = await axios.get(repositoriesUrl) + const snapshotsResp = await axios.get(snapshotsUrl) - const resp = getComponentLogStats(snapshotsResp.data) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/name`, + value: repositoriesResp.data?.spec.encryptionSecret.name, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/namespace`, + value: repositoriesResp.data?.spec.encryptionSecret.namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/name`, + value: `${refDBName}-full`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/name`, + value: `${refDBName}-manifest`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: convertToLocal(resp?.end), - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: convertToLocal(resp?.start), - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: convertToLocal(resp?.end), - force: true, - }) - } catch (e) { - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: '', - force: true, - }) - console.log(e) - } -} + const resp = getComponentLogStats(snapshotsResp.data) -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: convertToLocal(resp?.end), + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: convertToLocal(resp?.start), + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: convertToLocal(resp?.end), + force: true, + }) + } catch (e) { + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: '', + force: true, + }) + console.log(e) + } } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) - } - return options -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - setPointInTimeRecovery, - getRecoveryNames, - fetchNamespaces, - showRecovery, - returnFalse, - initBundle, - EqualToDatabaseMode, - isVariantAvailable, - showAuthPasswordField, - getNamespaces, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - isMachineNotCustom, - isMachineCustom, - showMonitoringSection, - setMonitoringStatus, - updateAlertValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - getNodeTopology, - filterNodeTopology, - getAdminOptions, - isToggleOn, - showAlerts, - showIssuer, - onBackupSwitch, - setMonitoring, - onAuthChange, - isConfigDatabaseOn, - clearConfiguration, - setBackup, - showAdditionalSettings, - getDefault, - onArchiverChange, - showArchiverAlert, - showArchiver, + return { + onReferSecretChange, + showReferSecretSwitch, + getDefaultValue, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + setPointInTimeRecovery, + isRancherManaged, + getRecoveryNames, + fetchNamespaces, + showRecovery, + showAdditionalSettings, + returnFalse, + initBundle, + isVariantAvailable, + showAuthPasswordField, + EqualToDatabaseMode, + getNamespaces, + isMachineNotCustom, + isMachineCustom, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAlertValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + getNodeTopology, + filterNodeTopology, + getAdminOptions, + isToggleOn, + showAlerts, + showIssuer, + onBackupSwitch, + setMonitoring, + onAuthChange, + isConfigDatabaseOn, + clearConfiguration, + setBackup, + getDefault, + onArchiverChange, + showArchiverAlert, + showArchiver, + } } diff --git a/charts/kubedbcom-mariadb-editor/ui/edit-ui.yaml b/charts/kubedbcom-mariadb-editor/ui/edit-ui.yaml index ae08223d16..a09d7333b3 100644 --- a/charts/kubedbcom-mariadb-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-mariadb-editor/ui/edit-ui.yaml @@ -1,1300 +1,691 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - fetch: getResources|core|v1|namespaces - label: - text: labels.namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - disableUnselect: true - disabled: true - fetch: getMariaDbVersions|catalog.kubedb.com|v1alpha1|mariadbversions - label: - text: labels.database.version - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/version - type: select - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/deletionPolicy - type: radio - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/authSecret/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - elements: - - alias: reusable_alert - chart: - name: uibytebuildersdev-component-alert - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/form/properties/alert - type: reusable-element - type: single-step-form - id: alert - title: labels.alert -- form: - discriminator: - activeDatabaseMode: - default: Standalone - type: string +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - if: isEqualToDatabaseMode|Cluster - label: - text: labels.to_update_disabled_section - type: label-element - - customClass: mb-20 - if: isEqualToDatabaseMode|Cluster - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mariadbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations - - computed: setDatabaseMode - disabled: true - hasDescription: true - label: - text: labels.database.mode - onChange: deleteDatabaseModePath + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - description: options.database.mode.Standalone.description - text: options.database.mode.Standalone.label - value: Standalone - - description: options.database.mode.Cluster.description - text: options.database.mode.Cluster.label - value: Cluster - schema: - $ref: discriminator#/activeDatabaseMode - type: radio - - disabled: true - if: isEqualToDatabaseMode|Cluster - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/replicas - type: input - - disabled: true + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - fetch: getStorageClassNames - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/storage/properties/storageClassName - type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/storage/properties/resources/properties/requests/properties/storage - type: input - type: single-step-form - type: single-step-form - id: topology - title: steps.1.label -- form: - discriminator: - configureTLS: - default: true - type: boolean - elements: - - label: - text: labels.to_update_tls - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mariadbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=ReconfigureTLS - - computed: isValueExistInModel|/resources/kubedbComMariaDB/spec/tls - disabled: true - label: - text: labels.enable_tls - onChange: onTlsConfigureChange - schema: - $ref: discriminator#/configureTLS - type: switch - - disabled: true - elements: - - label: - text: labels.require_ssl_question - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/requireSSL - type: switch - - elements: - - computed: setApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - title: steps.2.label -- form: + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig + elements: + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - disabled: disableInitializationSection - discriminator: - prePopulateDatabase: - type: string - elements: - - computed: initPrePopulateDatabase - label: - text: labels.prePopulateDatabase - onChange: onPrePopulateDatabaseChange + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getMariaDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/prePopulateDatabase - type: radio - - discriminator: - dataSource: - type: string + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - computed: initDataSource - label: - text: labels.dataSource - onChange: onDataSourceChange - options: - - text: options.dataSource.script.text - value: script - - text: options.dataSource.stashBackup.text - value: stashBackup - schema: - $ref: discriminator#/properties/dataSource - type: select - - discriminator: - sourceVolumeType: - type: string - elements: - - label: - text: labels.script.path - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/init/properties/script/properties/scriptPath - type: input - - label: - text: labels.script.volume - type: label-element - - computed: initVolumeType - label: - text: labels.script.volumeType - onChange: onVolumeTypeChange - options: - - text: options.scriptSourceVolumeType.configMap.text - value: configMap - - text: options.scriptSourceVolumeType.secret.text - value: secret - schema: - $ref: discriminator#/properties/sourceVolumeType - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|configmaps - if: showConfigMapOrSecretName|configMap - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/init/properties/script/properties/configMap/properties/name - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|secrets - if: showConfigMapOrSecretName|secret - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/init/properties/script/properties/secret/properties/secretName - type: select - if: showScriptOrStashForm|script - type: single-step-form - - elements: - - label: - text: labels.restoreSession.snapshot - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/rules/properties/0/properties/snapshots/properties/0 - type: input - - discriminator: - repositoryChoise: - type: string + # mariadb mode + - type: switch + label: Trigger + fullwidth: true + init: + type: func + value: setTrigger|autoscalingKubedbComMariaDBAutoscaler/spec/compute/mariadb/trigger + schema: temp/properties/compute/properties/mariadb/properties/trigger + watcher: + func: onTriggerChange|compute/mariadb + paths: + - temp/properties/compute/properties/mariadb/properties/trigger + - type: label-element + label: Pod lifetime threshold + subtitle: Specifies the duration a pod can exist before using considered for scaling decisions, ensuring resource optimization and workload stability + - type: input + label: Pod LifeTime Threshold (e.g., 10m 30s) + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/podLifeTimeThreshold + customClass: width-300 + - type: block-layout + label: Mariadb + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb elements: - - label: - text: labels.repositories.title - type: label-element - - computed: setInitialRestoreSessionRepo - onChange: onInitRepositoryChoiseChange - options: - - text: options.createOrSelect.select.text - value: select - - text: options.createOrSelect.create.text - value: create - schema: - $ref: discriminator#/properties/repositoryChoise - type: radio - - allowUserDefinedOption: true - fetch: resourceNames|stash.appscode.com|v1alpha1|repositories - if: showRepositorySelectOrCreate|select - label: - text: labels.repositories.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/repository/properties/name - type: select - - alias: repository_create_init - chart: - name: uibytebuildersdev-component-repository-create - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRepositorySelectOrCreate|create - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRepository_init_repo/properties/spec/properties/backend - type: reusable-element - type: single-step-form - - if: returnFalse - label: - text: labels.backupConfiguration.targetReference.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/target/properties/ref/properties/name - type: input - - discriminator: - customizeRestoreJobRuntimeSettings: - type: string + - type: threshold-input + label: ResourceDiff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/resourceDiffPercentage + customClass: width-300 + - type: label-element + label: Resource Configuration + subtitle: Define minimum and maximum allowed resources to ensure optimal database performance + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|mariadb + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|mariadb + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|mariadb + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology elements: - - computed: initCustomizeRestoreJobRuntimeSettings - label: - isSubsection: true - text: labels.runtimeSettings.choise - onChange: onCustomizeRestoreJobRuntimeSettingsChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/customizeRestoreJobRuntimeSettings - type: radio - - alias: runtime_settings_init - chart: - name: uibytebuildersdev-component-runtime-settings - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRuntimeForm|yes - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/runtimeSettings - type: reusable-element - type: single-step-form - if: showScriptOrStashForm|stashBackup - type: single-step-form - - if: returnFalse - label: - text: labels.waitForInitialRestore - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/init/properties/waitForInitialRestore - type: switch - if: showInitializationForm - type: single-step-form - type: single-step-form - type: single-step-form - id: initialization - title: steps.3.label -- form: - discriminator: - repoInitialSelectionStatus: - type: string - scheduleBackup: - default: "yes" - type: string - elements: - - computed: initScheduleBackupForEdit - if: showScheduleBackup - label: - text: labels.backup.title - onChange: onScheduleBackupChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/scheduleBackup - type: radio - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean - elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string - elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean - elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean - elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - if: showBackupForm - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.4.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComMariaDB/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean + - type: block-layout + showLabels: false elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMariaDB/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMariaDB/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMariaDB/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - elements: - - elements: - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - type: single-step-form - id: pod-template - title: steps.6.label -- form: - elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.7.label -- form: - elements: - - elements: - - discriminator: - configuration: - type: string - configurationSource: - default: use-existing-config - type: string - elements: - - label: - text: labels.to_update_config - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mariadbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=Reconfigure - - disabled: true - label: - text: labels.custom_config - onChange: onConfigurationSourceChange + - type: switch + label: Trigger + fullwidth: true + init: + type: func + value: setTrigger|autoscalingKubedbComMariaDBAutoscaler/spec/storage/mariadb/trigger + schema: temp/properties/storage/properties/mariadb/properties/trigger + watcher: + func: onTriggerChange|storage/mariadb + paths: + - temp/properties/storage/properties/mariadb/properties/trigger + - type: label-element + label: Expansion Mode (Online/Offline) + subtitle: For Online Mode enables scaling without downtime by dynamically resizing storage while the database remains operational and Offline Mode performs storage scaling during scheduled downtime, ensuring consistency but requiring database restarts. + - type: select + label: Mode + description: Select how the storage expansion should be handled. options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/configurationSource - type: radio - - allowUserDefinedOption: true - disabled: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSource - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/configSecret/properties/name - type: select - type: single-step-form - type: single-step-form - type: single-step-form - id: custom-config - title: steps.8.label -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getMariaDbs - label: - text: SelectDb - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: SelectType - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array - elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComMariaDBAutoscaler/spec/compute/mariadb/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/expansionMode + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: Mariadb + showLabels: true elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|mariadb - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|mariadb - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|mariadb - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb/properties/controlledResources - type: multiselect - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb - type: single-step-form - label: - text: Mariadb - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - if: ifScalingTypeEqualsTo|compute - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.9.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: threshold-input + label: UsageThreshold (%) + subtitle: Set the threshold percentage of storage usage to trigger scaling. + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/usageThreshold + customClass: width-300 + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComMariaDB/spec/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComMariaDBAutoscaler/spec/storage/mariadb/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/scalingRules + # elements: + # - type: input + # label: AppliesUpto (In Storage units) + # schema: appliesUpto + # - type: input + # label: Threshold (In %, Or In Storage Units) + # schema: threshold + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComMariaDBAutoscaler/spec/storage/mariadb/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getMariaDbs - label: - text: SelectDb - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: SelectType - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComMariaDBAutoscaler/spec/storage/mariadb/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/trigger - type: select - - label: - text: Expansion Mode + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComMariaDB/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection + elements: + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/expansionMode - type: select - - label: - text: Usage Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMariaDB/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMariaDB/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: Applies Upto - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: Applies Upto - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/storage/properties/mariadb/properties/upperBound - type: input - label: - text: Mariadb - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/compute/properties/mariadb - show_label: true - type: single-step-form - if: ifScalingTypeEqualsTo|storage - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMariaDBAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.10.label -- form: - discriminator: - binding: - default: false - type: boolean + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMariaDB/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: + type: input + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMariaDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: binding + label: Gateway Binding elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -type: multi-step-form + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-mariadb-editor/ui/functions.js b/charts/kubedbcom-mariadb-editor/ui/functions.js index 4f886a73d9..08f47e9087 100644 --- a/charts/kubedbcom-mariadb-editor/ui/functions.js +++ b/charts/kubedbcom-mariadb-editor/ui/functions.js @@ -1,2605 +1,1467 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + /************* Backup Configuration *************/ + + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} + initRepositoryChoiseForEdit() -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' + } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + function initScheduleBackup() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' + } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, + function getBackupConfigsAndAnnotations(getValue, model) { + const stashAppscodeComBackupConfiguration = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration', ) + const kubedbComMariaDBAnnotations = + getValue(model, '/resources/kubedbComMariaDB/metadata/annotations') || {} - const resources = (resp && resp.data && resp.data.items) || [] + const isBluePrint = Object.keys(kubedbComMariaDBAnnotations).some( + (k) => + k === 'stash.appscode.com/backup-blueprint' || + k === 'stash.appscode.com/schedule' || + k.startsWith('params.stash.appscode.com/'), + ) - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + return { + stashAppscodeComBackupConfiguration, + isBluePrint, + } } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + function onScheduleBackupChange() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (scheduleBackup === 'no') { + // delete stashAppscodeComBackupConfiguration + commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + // delete annotation from kubedbComMariaDB annotation + deleteKubeDbComMariaDbAnnotation(getValue, model, commit) + } else { + const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + // create stashAppscodeComBackupConfiguration and initialize it if not exists - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const dbName = getValue(model, '/metadata/release/name') - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + if ( + !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && + !isBluePrint + ) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration', + value: stashAppscodeComBackupConfiguration, + }) + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + } + } } - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + function deleteKubeDbComMariaDbAnnotation(getValue, model, commit) { + const annotations = getValue(model, '/resources/kubedbComMariaDB/metadata/annotations') || {} + const filteredKeyList = + Object.keys(annotations).filter( + (k) => + k !== 'stash.appscode.com/backup-blueprint' && + k !== 'stash.appscode.com/schedule' && + !k.startsWith('params.stash.appscode.com/'), + ) || [] + const filteredAnnotations = {} + filteredKeyList.forEach((k) => { + filteredAnnotations[k] = annotations[k] + }) + commit('wizard/model$update', { + path: '/resources/kubedbComMariaDB/metadata/annotations', + value: filteredAnnotations, }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) } - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + // backup form + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let namespaceList = [] + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComMariaDB') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + // get values.yaml to populate data when backup-config is being created + try { + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` -function returnTrue() { - return true -} + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` -function returnStringYes() { - return 'yes' -} + const resp = await axios.get(url) -// ************************* Basic Info ********************************************** -async function getMariaDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} + } catch (e) { + console.log(e) + } - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } + } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, + // check config with metadata name first + let config = configs?.find( + (item) => + item.metadata?.name === name && + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, ) - const resources = (resp && resp.data && resp.data.items) || [] + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + // set backup switch here + isBackupOn = !!config - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] - } -} + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset -// ************************* Auth Secret Field ****************************************** -function showAuthPasswordField({ model, getValue, watchDependency }) { - watchDependency('model#/resources') - const modelPathValue = getValue(model, '/resources') - return !!( - modelPathValue && - modelPathValue.secret && - modelPathValue.secret.metadata && - modelPathValue.secret.metadata.name && - !showAuthSecretField({ model, getValue, watchDependency }) - ) -} + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends -function showAuthSecretField({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComMariaDB/spec') - const modelPathValue = getValue(model, '/resources/kubedbComMariaDB/spec') - return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) -} + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` -function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { - const resp = - !showAuthSecretField({ model, getValue, watchDependency }) && - !showAuthPasswordField({ model, getValue, watchDependency }) - const secret = getValue(model, '/resources/secret_auth') - if (resp && !secret) { - commit('wizard/model$update', { - path: '/resources/secret_auth', - value: { - data: { - password: '', - }, - }, - force: true, - }) - } - return resp -} + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions + } -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/resources/kubedbComMariaDB/spec/replicas') - watchDependency('model#/resources/kubedbComMariaDB/spec/replicas') + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } - if (modelPathValue > 1) { - return 'Cluster' - } else { - return 'Standalone' + setDiscriminatorValue('isBackupDataLoaded', true) } -} - -let storageClassList = [] -async function getStorageClassNames({ axios, storeGet, commit, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - storageClassList = resources - const initialStorageClass = getValue( - model, - '/resources/kubedbComMariaDB/spec/storage/storageClassName', - ) - if (!initialStorageClass) setStorageClass({ model, getValue, commit }) - return resources -} - -function setStorageClass({ model, getValue, commit }) { - const deletionPolicy = getValue(model, '/resources/kubedbComMariaDB/spec/deletionPolicy') || '' - let storageClass = - getValue(model, '/resources/kubedbComMariaDB/spec/storage/storageClassName') || '' - const suffix = '-retain' - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') + } - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + function setBackupType() { + return 'BackupConfig' + } - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function getTypes() { + const arr = [ + { + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', + }, + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) } + return arr } - if (storageClass) { + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/storage/storageClassName', - value: storageClass, + path: '/backupType', + value: type, force: true, }) - } -} - -function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - if (mode === 'Cluster') { - replicas = getValue(model, '/resources/kubedbComMariaDB/spec/replicas') - if (!replicas) { + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/replicas', - value: 3, + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), force: true, }) } - } else if (mode === 'Standalone') { - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/replicas') + commit('wizard/model$delete', '/context') + commit('wizard/model$update', { + path: '/resources/kubedbComMariaDB', + value: objectCopy(dbResource), + force: true, + }) } -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} -// ************************** TLS ******************************88 + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') -function setApiGroup() { - return 'cert-manager.io' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComMariaDB/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComMariaDB/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComMariaDB/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComMariaDB/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + return selectedType === type } - if (!url) return [] + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations - try { - const resp = await axios.get(url) + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) + } - const resources = (resp && resp.data && resp.data.items) || [] + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') + if (blueprintSwitch) addLabelAnnotation('annotations') + else deleteLabelAnnotation('annotations') + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComMariaDB/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) + } else { + commit('wizard/model$delete', path) + } + } - return !!(resp && resp.length) -} + function addLabelAnnotation(type) { + const obj = objectCopy(initialDbMetadata[type]) -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` + } else { + obj['kubedb.com/archiver'] = 'true' + } - return !resp -} + commit('wizard/model$update', { + path: `/resources/kubedbComMariaDB/metadata/${type}`, + value: obj, + force: true, + }) + } -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComMariaDB/spec/sslMode') - return val || 'require' -} + function deleteLabelAnnotation(type) { + const obj = initialDbMetadata[type] -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/tls', - value: { issuerRef: {}, certificates: [] }, + path: `/resources/kubedbComMariaDB/metadata/${type}`, + value: obj, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/sslMode') } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/monitor', - value: {}, + path: '/context', + value: context, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/monitor') + if (context === 'Create') { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, + force: true, + }) + } + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) } - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) + const list = filteredList?.map((ele) => ele.metadata.name) + return list + } -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/monitor/prometheus/exporter', - value: {}, + path: '/resources/coreKubestashComBackupConfiguration', + value: configDetails, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/monitor/prometheus/exporter') } -} -// ********************************* Initialization & Backup ************************************* -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' + } -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' + } -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName + } -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComMariaDB/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComMariaDB/spec/init/script') + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' + } -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) + + return repoInitialSelectionStatus + } + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, + path: modelPath, + value: session, }) } } -} -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComMariaDB/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') + const resources = (resp && resp.data && resp.data.items) || [] - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComMariaDB/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/init/script', - value: initScript, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/init/script') + return resources + } catch (e) { + console.log(e) + return [] + } + } - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) } - } -} -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComMariaDB/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComMariaDB/spec/init/script/secret/secretName') + return ans + } - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value + } -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/init/script/secret') + /****** Monitoring *********/ - if (!valueExists(model, getValue, '/resources/kubedbComMariaDB/spec/init/script/configMap')) { - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/init/script/configMap') + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } - if (!valueExists(model, getValue, '/resources/kubedbComMariaDB/spec/init/script/secret')) { + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/init/script/secret', - value: { - secretName: '', - }, + path: '/resources/kubedbComMariaDB/spec/monitor', + value: {}, + force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/monitor') } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} - -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', + force: true, }) } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus } -} -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + path: '/resources/kubedbComMariaDB/spec/monitor/prometheus/exporter', value: {}, force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/monitor/prometheus/exporter') } } -} -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComMariaDB/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComMariaDB/spec/metadata/labels') - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) + const agent = getValue(model, '/resources/kubedbComMariaDB/spec/monitor/agent') - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + } -// FOR Backup Configuration + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComMariaDB/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) -// schedule bakcup + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } + } -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComMariaDBAnnotations = - getValue(model, '/resources/kubedbComMariaDB/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComMariaDBAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - } -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -function deleteKubeDbComMariaDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComMariaDB/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/metadata/annotations', - value: filteredAnnotations, - }) -} + const secrets = (resp && resp.data && resp.data.items) || [] -function addKubeDbComMariaDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComMariaDB/metadata/annotations') || {} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } } - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + /************* Compute Autoscaling *************/ - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) + let autoscaleType = '' + let dbDetails = {} - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') || + '' - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mariadbs/${name}`, + ) + dbDetails = resp.data || {} -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComMariaDB annotation - deleteKubeDbComMariaDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, + }) + } - // create stashAppscodeComBackupConfiguration and initialize it if not exists + function isKubedb() { + return !!storeGet('/route/params/actions') + } - const dbName = getValue(model, '/metadata/release/name') + function isConsole() { + const isKube = isKubedb() - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { + if (isKube) { + const dbName = storeGet('/route/params/name') || '' commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, + path: '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, + path: '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/name', + value: modifiedName, force: true, }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } + + return !isKube } -} -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - if (scheduleBackup === 'yes') return true - else return false -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') + const resources = (resp && resp.data && resp.data.items) || [] - return databaseName -} + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComMariaDB/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} + async function getMariaDbs() { + // watchDependency('model#/metadata/namespace') + const namespace = getValue(model, '/metadata/namespace') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mariadbs`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - return repoInitialSelectionStatus -} + const resources = (resp && resp.data && resp.data.items) || [] -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') || + '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, + path: '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/name', + value: modifiedName, + force: true, }) + + // delete the other type object from vuex wizard model + if (type === 'compute') + commit('wizard/model$delete', '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/storage') + if (type === 'storage') + commit('wizard/model$delete', '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute') + } + + async function fetchTopologyMachines() { + const instance = hasAnnotations() + + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) + + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } } } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComMariaDB/metadata/annotations') - return { ...annotations } || {} -} + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} + return value === 'On' + } -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComMariaDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} + function onTriggerChange(type) { + const trigger = getValue(discriminator, `/${type}/trigger`) + const commitPath = `/resources/autoscalingKubedbComMariaDBAutoscaler/spec/${type}/trigger` -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComMariaDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} + commit('wizard/model$update', { + path: commitPath, + value: trigger ? 'On' : 'Off', + force: true, + }) + } -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') + return !!instance + } - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComMariaDB/metadata/annotations') || {} - const newAnnotations = {} + function setAllowedMachine(minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/annotations') || {} + const instance = annotations?.['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) + if (minmax === 'min') return mn + else return mx + } - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/metadata/annotations', - value: newAnnotations, - }) -} + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComMariaDB/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComMariaDB/spec/metadata/labels') - const agent = getValue(model, '/resources/kubedbComMariaDB/spec/monitor/agent') + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) + return dependantIndex === -1 ? machines : filteredMachine } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - const agent = getValue(model, '/resources/kubedbComMariaDB/spec/monitor/agent') + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] - const labels = getValue(model, '/resources/kubedbComMariaDB/spec/metadata/labels') + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute/${type}` - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, force: true, }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, + path: annoPath, + value: { ...annotations }, force: true, }) } } - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) + function hasNoAnnotations() { + return !hasAnnotations() } -} - -function returnFalse() { - return false -} -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComMariaDB/spec/monitor/agent') - if (agent === 'prometheus.io') { + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute/${type}/controlledResources` commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], + path: path, + value: list, force: true, }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + return list } -} -/************************************* Database Secret Section ********************************************/ + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] + } -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComMariaDB/spec/authSecret') + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } - return !authSecret -} + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') && + !!getValue(discriminator, '/autoscalingType') + ) + } -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} + function setApplyToIfReady() { + return 'IfReady' + } -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} + /************* Monitoring *************/ -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') + const isKube = !!storeGet('/route/params/actions') - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mariadbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` } -} -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComMariaDB/spec/init/initialized') - watchDependency('model#/resources/kubedbComMariaDB/spec/init/initialized') - return !!initialized -} + function onNamespaceChange() { + const namespace = getValue(model, '/metadata/namespace') + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name', + ) + } + } -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] - } -} - -//////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/md-config.cnf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/md-config.cnf') -} - -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/md-config.cnf') - return atob(value) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComMariaDB/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - } -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mariadbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -function getNamespaceArray() { - return namespaceList -} - -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` - - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' } else { - return resp.data?.status?.namespaces || [] + return 'input' } - } catch (e) { - console.log(e) } - return [] -} -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) } - } catch (e) { - console.log(e) - } - return [] -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - force: true, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) || [] - if (session.length) { - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) - } -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} - -async function initBackupData({ commit, storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComMariaDB') - initialDbMetadata = objectCopy(dbResource.metadata) - initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check storageclass archiver annotation - if (initialArchiver) { - isArchiverAvailable = true - } else { - const storageClassName = dbResource?.spec?.storage?.storageClassName - const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` - try { - const resp = await axios.get(url) - const archAnnotation = resp.data?.metadata?.annotations - const annotationKeyToFind = `${resource}.${group}/archiver` - if (archAnnotation[annotationKeyToFind]) { - isArchiverAvailable = true - archiverObjectToCommit = { - ref: { - name: archAnnotation[annotationKeyToFind], - namespace: 'kubedb', - }, - } - } - } catch (e) { - console.log(e) - } - } - - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // set backup switch here - isBackupOn = !!config - - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends - - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` - - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions - } - - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, } - setDiscriminatorValue('isBackupDataLoaded', true) -} -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} - -async function setBackupType() { - return 'BackupConfig' -} - -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - - if (dbResource?.spec?.replicas !== 1 && isArchiverAvailable) { - arr.push({ - description: 'Enable/Disable Archiver', - text: 'Archiver', - value: 'Archiver', - }) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } - return arr -} -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), - force: true, - }) - } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComMariaDB', - value: objectCopy(dbResource), - force: true, - }) -} - -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') - - return selectedType === type -} - -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations - - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} - -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} - -function onArchiverChange({ getValue, discriminator, commit, model, storeGet }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComMariaDB/spec/archiver' - if (archiverSwitch) { - commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - } else { - commit('wizard/model$delete', path) - } -} - -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) - - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' - } - - commit('wizard/model$update', { - path: `/resources/kubedbComMariaDB/metadata/${type}`, - value: obj, - force: true, - }) -} - -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] - - commit('wizard/model$update', { - path: `/resources/kubedbComMariaDB/metadata/${type}`, - value: obj, - force: true, - }) -} - -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, - force: true, + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } -} -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} - -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} - -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComMariaDB/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} + if (!configMapName) return [] -//////////////// Autoscaler ////////// + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) -let autoscaleType = '' -let dbDetails = {} + const configMaps = (resp && resp.data && resp.data.data) || {} -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: namespace, - force: true, - }) + return configMapKeys + } catch (e) { + console.log(e) + return [] } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getMariaDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/metadata/namespace') - const namespace = getValue(model, '/metadata/namespace') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mariadbs`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + const secrets = (resp && resp.data && resp.data.items) || [] - const resources = (resp && resp.data && resp.data.items) || [] + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] } - }) -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from vuex wizard model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue(model, '/metadata/namespace') - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name', - ) } -} - -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} - -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( model, - '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} + '/resources/kubedbComMariaDB/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + if (!secretName) return [] -function setApplyToIfReady() { - return 'IfReady' -} - -async function getDbDetails({ setDiscriminatorValue, commit, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mariadbs/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) + + const secret = (resp && resp.data && resp.data.data) || {} + + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) + + return secretKeys } catch (e) { console.log(e) + return [] } } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComMariaDBAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} + /************* Binding *************/ -function objectCopy(obj) { - const temp = JSON.stringify(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 -} + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const 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 labels = getValue(model, '/resources/kubedbComMariaDB/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'MariaDBBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComMariaDB/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'MariaDBBinding', + metadata: { + labels, 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') + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComMariaDBBinding', + value: bindingValues, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComMariaDBBinding') + } } -} - -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + function returnFalse() { + return false + } - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } } } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComMariaDBAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComMariaDBAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + return { + initScheduleBackup, + initScheduleBackupForEdit, + onScheduleBackupChange, + showBackupForm, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + onBackupTypeChange, + isBackupType, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showConfigList, + showSchedule, + showScheduleBackup, + getDefaultSchedule, + onInputChangeSchedule, + getBackupConfigsAndAnnotations, + deleteKubeDbComMariaDbAnnotation, + valueExists, + + getDbDetails, + isKubedb, + isConsole, + getNamespaces, + isRancherManaged, + onNamespaceChange, + getMariaDbs, + initMetadata, + fetchTopologyMachines, + setTrigger, + onTriggerChange, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + setControlledResources, + fetchNodeTopology, + isNodeTopologySelected, + showOpsRequestOptions, + setApplyToIfReady, + setValueFromDbDetails, + + handleUnit, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + + isBindingAlreadyOn, + addOrRemoveBinding, + returnFalse, } } - -return { - getDbDetails, - isConsole, - getNamespaces, - getMariaDbs, - isKubedb, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - fetchNames, - isRancherManaged, - fetchNamespaces, - onInputChangeSchedule, - getDefaultSchedule, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - getMariaDbVersions, - showAuthPasswordField, - showAuthSecretField, - showNewSecretCreateField, - setDatabaseMode, - getStorageClassNames, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComMariaDbAnnotation, - addKubeDbComMariaDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - disableInitializationSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - getCreateNameSpaceUrl, - setStorageClass, - - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - getNamespaceArray, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, -} diff --git a/charts/kubedbcom-memcached-editor-options/ui/create-ui.yaml b/charts/kubedbcom-memcached-editor-options/ui/create-ui.yaml index b3c2e1f530..3807dde82b 100644 --- a/charts/kubedbcom-memcached-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-memcached-editor-options/ui/create-ui.yaml @@ -1,255 +1,227 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Memcached/versions + if: + type: function + name: isToggleOn|databases/Memcached/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Memcached/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Memcached/mode + loader: getAdminOptions|databases/Memcached/mode + if: + type: function + name: isToggleOn|databases/Memcached/mode + isHorizontal: true + label: Database mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + label: Replicaset number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine_profile + showLabels: true + type: block-layout + - description: Configure Credentials, Deployment Mode etc. elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Memcached/versions - if: isToggleOn|databases/Memcached/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Memcached/properties/versions/properties/default + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - computed: getDefault|databases/Memcached/mode - fetch: getAdminOptions|databases/Memcached/mode - hasDescription: true - if: isToggleOn|databases/Memcached/mode - label: - text: labels.database.mode - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: isEqualToModelPathValue|Replicaset|/spec/mode - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - init: + type: func + value: setMonitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - if: isToggleOn|monitoring - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|monitoring + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-memcached-editor-options/ui/functions.js b/charts/kubedbcom-memcached-editor-options/ui/functions.js index 67b50d4b73..bc872cd5dd 100644 --- a/charts/kubedbcom-memcached-editor-options/ui/functions.js +++ b/charts/kubedbcom-memcached-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,743 +317,761 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } + + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -async function getMemcachedVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getMemcachedVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, }, - }, - } + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - // keep only non deprecated versions - const filteredMemcachedVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + // keep only non deprecated versions + const filteredMemcachedVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - filteredMemcachedVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMemcachedVersions -} + filteredMemcachedVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMemcachedVersions + } -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const secrets = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + const secrets = (resp && resp.data && resp.data.items) || [] - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - } else { - array = machineList - .map((machine) => { + return filteredSecrets + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) - commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, - force: true, - }) - commit('wizard/model$update', { - path: comparePath, - value: cpu, - force: true, - }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} - -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} - -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const isAlertToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'alert', - ) - return isMonitorEnabled && isAlertToggleEnabled -} - -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} - -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} - -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} - -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} - -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} - -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} - -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} - -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue } -} -function updateAgentValue({ commit, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Memcached/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Memcached/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Memcached/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') } - if (!features.includes('binding')) { + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, + path: '/form/alert/enabled', + value: alert, force: true, }) - } - if (!features.includes('monitoring')) { + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { path: '/spec/admin/monitoring/agent', - value: '', + value: agent, force: true, }) + } + + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - if (!features.includes('backup')) { + + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } + + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } + + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } + + function onAuthChange() { commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, + path: '/spec/authSecret/name', + value: '', force: true, }) commit('wizard/model$update', { - path: '/spec/backup/tool', + path: '/spec/authSecret/password', value: '', force: true, }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') + + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` + function updateAgentValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) } - return returnArray -} + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + } catch (e) { + console.log(e) + } -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + commit('wizard/model$update', { + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), + force: true, + }) - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!getValue(model, `/spec/admin/databases/Memcached/mode/toggle`)) { + let defMode = getDefault('databases/Memcached/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Memcached/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + setDiscriminatorValue('/bundleApiLoaded', true) } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } + + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function returnFalse() { + return false + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - updateAlertValue, - showAdditionalSettings, - initBundle, - returnFalse, - isVariantAvailable, - showAuthPasswordField, - isEqualToModelPathValue, - getNamespaces, - getMemcachedVersions, - getSecrets, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - isMachineNotCustom, - isMachineCustom, - getCreateNameSpaceUrl, - showAlerts, - onBackupSwitch, - showIssuer, - setMonitoring, - onAuthChange, - isConfigDatabaseOn, - clearConfiguration, - getNodeTopology, - filterNodeTopology, - updateAgentValue, - getAdminOptions, - isToggleOn, - setBackup, - getDefault, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + updateAlertValue, + showAdditionalSettings, + initBundle, + returnFalse, + isVariantAvailable, + showAuthPasswordField, + isEqualToModelPathValue, + getNamespaces, + getMemcachedVersions, + getSecrets, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + isMachineNotCustom, + isMachineCustom, + getCreateNameSpaceUrl, + showAlerts, + onBackupSwitch, + showIssuer, + setMonitoring, + onAuthChange, + isConfigDatabaseOn, + clearConfiguration, + getNodeTopology, + filterNodeTopology, + updateAgentValue, + getAdminOptions, + isToggleOn, + setBackup, + getDefault, + } } diff --git a/charts/kubedbcom-memcached-editor/ui/edit-ui.yaml b/charts/kubedbcom-memcached-editor/ui/edit-ui.yaml index 3fa8e3ac7e..44ece4161e 100644 --- a/charts/kubedbcom-memcached-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-memcached-editor/ui/edit-ui.yaml @@ -1,460 +1,458 @@ -steps: -- form: - discriminator: - dbDetails: - default: false - type: boolean +type: multi-step-form +step: + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComMemcached/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComMemcachedAutoscaler/spec/compute/memcached/trigger - label: - text: Trigger + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMemcached/spec/monitor/agent elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|memcached - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|memcached - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|memcached - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/controlledResources - type: multiselect - label: - text: Memcached - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMemcached/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMemcached/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: + type: input + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComMemcached/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMemcached/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMemcached/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMemcached/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMemcached/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -type: multi-step-form + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines + elements: + # memcached mode + - type: block-layout + label: Memcached + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMemcachedAutoscaler/spec/compute/memcached/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|memcached + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|memcached + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|memcached + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/memcached/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: select + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + options: + - text: 5 minutes + value: 5m0s + - text: 10 minutes + value: 10m0s + - text: 30 minutes + value: 30m0s + - text: 1 hour + value: 1h0m + - text: 2 hours + value: 2h0m + - text: 5 hours + value: 5h0m + - text: 10 hours + value: 10h0m + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMemcachedAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply \ No newline at end of file diff --git a/charts/kubedbcom-memcached-editor/ui/functions.js b/charts/kubedbcom-memcached-editor/ui/functions.js index da73f94ea3..72b7f8f6ab 100644 --- a/charts/kubedbcom-memcached-editor/ui/functions.js +++ b/charts/kubedbcom-memcached-editor/ui/functions.js @@ -1,2208 +1,820 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + setDiscriminatorValue('/enableMonitoring', false) + + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name') || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/memcacheds/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } } - }) -} - -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, + commit('wizard/model$update', { + path: `/metadata/release/name`, value: name, - } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} -function setAddressType({ model, getValue }) { - const value = getValue(model, '/resources/kubedbComMemcached/spec/useAddressType') - - if (!value) { - return 'DNS' - } - - return value -} - -// ************************* Basic Info ********************************************** -async function getMemcachedVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] - } -} - -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue }) { - const replicas = getValue(model, '/resources/kubedbComMemcached/spec/replicas') - - return replicas === 1 ? 'Standalone' : 'Cluster' -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} - -const onDatabaseModeChange = ({ discriminator, getValue, commit }) => { - const databaseMode = getValue(discriminator, '/activeDatabaseMode') - - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/replicas', - value: databaseMode === 'Standalone' ? 1 : 3, - force: true, - }) -} - -// ************************** TLS ******************************88 - -function setApiGroup() { - return 'cert-manager.io' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComMemcached/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComMemcached/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComMemcached/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComMemcached/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } - - if (!url) return [] - - try { - const resp = await axios.get(url) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComMemcached/spec/sslMode') - return val || 'require' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/tls', - value: { issuerRef: {}, certificates: [] }, + path: `/metadata/release/namespace`, + value: namespace, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/monitor', - value: {}, + path: `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name`, + value: name, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/monitor/prometheus/exporter', - value: {}, + path: `/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/monitor/prometheus/exporter') } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComMemcached/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComMemcached/spec/init/script') - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + let autoscaleType = '' + let dbDetails = {} -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) + function isConsole() { + const isKube = isKubedb() + if (isKube) { + const dbName = storeGet('/route/params/name') || '' commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', + path: '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name', value: dbName, force: true, }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComMemcached/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComMemcached/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, + path: '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/name', + value: modifiedName, force: true, }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComMemcached/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComMemcached/spec/init/script/secret/secretName') - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/init/script/secret') - - if (!valueExists(model, getValue, '/resources/kubedbComMemcached/spec/init/script/configMap')) { - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/init/script/configMap') - if (!valueExists(model, getValue, '/resources/kubedbComMemcached/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } + return !isKube } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + function isKubedb() { + return !!storeGet('/route/params/actions') + } - return repositoryChoise === value -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, + const resources = (resp && resp.data && resp.data.items) || [] + + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } -} -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace', ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name', ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule bakcup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComMemcachedAnnotations = - getValue(model, '/resources/kubedbComMemcached/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComMemcachedAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - } -} - -function deleteKubeDbComMemcachedDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComMemcached/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubeDbComMemcachedDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComMemcached/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComMemcached annotation - deleteKubeDbComMemcachedDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) } } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -// invoker form -function initBackupInvoker({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration) return 'backupConfiguration' - else if (isBluePrint) return 'backupBlueprint' - else return undefined -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model }) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - - if (backupInvoker === 'backupConfiguration') { - // delete annotation and create backup config object - deleteKubeDbComMemcachedDbAnnotation(getValue, model, commit) - const dbName = getValue(model, '/metadata/release/name') - - if (!valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - // delete backup configuration object and create the annotation - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - addKubeDbComMemcachedDbAnnotation( - getValue, + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace') + const namespace = getValue( model, - commit, - 'stash.appscode.com/backup-blueprint', - '', + '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace', ) - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComMemcached/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComMemcachedDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComMemcachedDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComMemcached/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComMemcached/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComMemcached/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComMemcached/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComMemcached/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComMemcached/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) - } - - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComMemcached/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComMemcached/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComMemcached/spec/init/initialized') - watchDependency('model#/resources/kubedbComMemcached/spec/init/initialized') - return !!initialized -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - if (owner && cluster && namespace) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, - }, - }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - return [] -} -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name') || + '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, + path: '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/name', + value: modifiedName, force: true, }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/configSecret/name', - value: configSecretName, - force: true, - }) + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute', + ) } -} -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/user.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} + async function fetchTopologyMachines() { + const instance = hasAnnotations() -function onConfigurationChangeEdit({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - - commit('wizard/model$update', { - path: '/resources/secret_config/data/memcached.ini', - value: btoa(value), - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } - return 'use-existing-config' -} - -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/user.conf') -} -function setConfigurationForEdit({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/memcached.ini') - return atob(value) -} + function hasAnnotations() { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/user.conf') - return atob(value) -} + return !!instance + } -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') + function setAllowedMachine(minmax) { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') + if (minmax === 'min') return mn + else return mx } -} -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/memcachedopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` -const getAppbinding = async ({ axios, storeGet, getValue, watchDependency, rootModel }) => { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - const group = 'appcatalog.appscode.com' - const version = 'v1alpha1' - const resource = 'appbindings' + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - watchDependency('rootModel#/databaseRef/namespace') + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - const namespace = getValue(rootModel, '/databaseRef/namespace') + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - const resources = (resp && resp.data && resp.data.items) || [] + return dependantIndex === -1 ? machines : filteredMachine + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) + const instance = annotations['kubernetes.io/instance-type'] -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine -function onRefChange({ discriminator, getValue, commit }) { - const ref = getValue(discriminator, '/pgRef') || {} - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/database/databaseRef/name', - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComMemcached/spec/database/databaseRef/namespace', - value: ref.namespace || '', - force: true, - }) -} + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute/${type}` -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, - }, - }, + if (minMachine && maxMachine && instance !== minMaxMachine) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: { ...annotations }, + force: true, + }) + } } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, - ) - const resources = (resp && resp.data && resp.data.items) || [] - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] + + return !!instance } -} -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} + function hasNoAnnotations() { + return !hasAnnotations() + } -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } - if (isKube) { - const dbName = storeGet('/route/params/name') || '' + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute/${type}/controlledResources` commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name', - value: dbName, + path: path, + value: list, force: true, }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace', - value: namespace, - force: true, - }) - } + return list } - return !isKube -} + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} + function setApplyToIfReady() { + return 'IfReady' + } + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] + } -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) + } -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + } - const resources = (resp && resp.data && resp.data.items) || [] + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { + let ans = [] try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/memcacheds/${name}`, - ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items } catch (e) { console.log(e) } + + return ans } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, + }) -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - clearSpecModel({ commit }, verd) - return type === verd && spec -} -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/${autoscaleType}/cluster`, - ) + /****** Monitoring *********/ + + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus } -} -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name') || - '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComMemcached/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMemcached/spec/monitor') + } + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/name', - value: modifiedName, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) - - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name', - ) } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComMemcached/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit( + 'wizard/model$delete', + '/resources/kubedbComMemcached/spec/monitor/prometheus/exporter', + ) + } } - return [] -} -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComMemcached/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComMemcached/spec/metadata/labels') -function setApplyToIfReady() { - return 'IfReady' -} + const agent = getValue(model, '/resources/kubedbComMemcached/spec/monitor/agent') -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, force: true, }) } - } else { - if (!isNaN(value)) { - value += 'Gi' + } + + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComMemcached/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], force: true, }) + + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } } -} -function setMetadata({ storeGet, mode, commit }) { - const dbname = storeGet('/route/params/name') || '' - const namespace = storeGet('/route/query/namespace') || '' - if (mode === 'standalone-step') { - commit('wizard/model$update', { - path: '/metadata/release/name', - value: dbname, - force: true, - }) - commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, - force: true, - }) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + if (owner && cluster && namespace) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { + items: { + data: { username: null, password: null }, + metadata: { name: null }, + type: null, + }, + }, + }, + }, + ) + + const secrets = (resp && resp.data && resp.data.items) || [] + + const filteredSecrets = secrets.filter((item) => { + const validType = [ + 'kubernetes.io/service-account-token', + 'Opaque', + 'kubernetes.io/basic-auth', + ] + return validType.includes(item.type) + }) + + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + } + } + return [] } -} -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const isKube = !!storeGet('/route/params/actions') - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/memcachedopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } + + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMemcachedAutoscaler/spec/databaseRef/name', + ) } } -} -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } + } - if (minmax === 'min') return mn - else return mx -} + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } + } -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComMemcached/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + if (!configMapName) return [] - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) + const configMaps = (resp && resp.data && resp.data.data) || {} - return dependantIndex === -1 ? machines : filteredMachine -} + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + return configMapKeys + } catch (e) { + console.log(e) + return [] + } + } - return !!instance -} + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComMemcached/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComMemcachedAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] + if (!secretName) return [] - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComMemcachedAutoscaler/spec/compute/${type}` + const secret = (resp && resp.data && resp.data.data) || {} - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) + + return secretKeys + } catch (e) { + console.log(e) + return [] + } } -} -return { - setMetadata, - isRancherManaged, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - isVariantAvailable, - fetchJsons, - getAppbinding, - onDatabaseModeChange, - setDatabaseMode, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - setAddressType, - getMemcachedVersions, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - valueExists, - onConfigurationChangeEdit, - setConfigurationForEdit, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComMemcachedDbAnnotation, - addKubeDbComMemcachedDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - setConfigurationForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - disableInitializationSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - onRefChange, - getAppBindings, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + function returnFalse() { + return false + } + + return { + returnFalse, + getDbDetails, + isConsole, + isKubedb, + getNamespaces, + onNamespaceChange, + getDbs, + initMetadata, + fetchTopologyMachines, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + isNodeTopologySelected, + setControlledResources, + setTrigger, + setApplyToIfReady, + fetchNodeTopology, + showOpsRequestOptions, + isEqualToModelPathValue, + getResources, + resourceNames, + // Monitoring + showMonitoringSection, + onEnableMonitoringChange, + showCustomizeExporterSection, + onCustomizeExporterChange, + isValueExistInModel, + // onNamespaceChange, + onLabelChange, + onAgentChange, + getSecrets, + getOpsRequestUrl, + setValueFrom, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + onValueFromChange, + isEqualToValueFromType, + getConfigMapKeys, + getSecretKeys, + } } diff --git a/charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml b/charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml index 32d49650ed..6e7523d61f 100644 --- a/charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml @@ -1,659 +1,662 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/MongoDB/versions - if: isToggleOn|databases/MongoDB/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/MongoDB/properties/versions/properties/default - type: select - - computed: getDefault|databases/MongoDB/mode - fetch: getAdminOptions|databases/MongoDB/mode - hasDescription: true - if: isToggleOn|databases/MongoDB/mode - label: - text: labels.database.mode - onChange: clearArbiterHidden - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - discriminator: - enableHorizons: - default: false - type: boolean - elements: - - label: - text: labels.replicaset.name - schema: - $ref: schema#/properties/spec/properties/replicaSet/properties/name +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/MongoDB/versions + if: + type: function + name: isToggleOn|databases/MongoDB/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/MongoDB/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/MongoDB/mode + loader: getAdminOptions|databases/MongoDB/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/MongoDB/mode + label: Database Mode + watcher: + func: clearArbiterHidden + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - elements: + - label: Replicaset Name + schema: schema/properties/spec/properties/replicaSet/properties/name + type: input + - label: Replicaset Number + watcher: + func: updateSuffix + paths: + - schema/properties/spec/properties/replicaSet/properties/replicas + schema: schema/properties/spec/properties/replicaSet/properties/replicas + type: input + - if: + type: function + name: isTlsOn + label: Do you want to access mongodb+srv style dns? + watcher: + func: onHorizonsChange + paths: + - discriminator/enableHorizons + schema: discriminator/enableHorizons + type: switch + - if: + type: function + name: isHorizonsOn + label: Horizons count should be equal to Replica Number. + type: alert + - type: array-item-form + element: + label: Add a new horizon dns for pod + schema: schema/properties/spec/properties/replicaSet/properties/horizons/items type: input - - label: - text: labels.replicaset.number - onChange: updateSuffix - schema: - $ref: schema#/properties/spec/properties/replicaSet/properties/replicas + if: + type: function + name: isHorizonsOn + label: Horizons + watcher: + func: updateSuffix + paths: + - schema/properties/spec/properties/replicaSet/properties/horizons + schema: schema/properties/spec/properties/replicaSet/properties/horizons + validation: + type: custom + name: isHorizonsValid + if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + type: block-layout + - elements: + - elements: + - customClass: mt-10 + label: Shards + schema: schema/properties/spec/properties/shardTopology/properties/shard/properties/shards type: input - - if: isTlsOn - label: - text: Do you want to access mongodb+srv style dns? - onChange: onHorizonsChange - schema: - $ref: discriminator#/enableHorizons - type: switch - - alertInfo: - show: true - type: neutral - if: isHorizonsOn - label: - text: Horizons count should be equal to Replica Number. - type: label-element - - element: - label: - text: Add a new horizon dns for pod - schema: - $ref: schema#/properties/spec/properties/replicaSet/properties/horizons/items + - label: Replicaset Number + schema: schema/properties/spec/properties/shardTopology/properties/shard/properties/replicas + type: input + - label: Storage size + schema: schema/properties/spec/properties/shardTopology/properties/shard/properties/persistence/properties/size + type: input + - elements: + - init: + type: func + value: setMachineToCustom|shardTopology/shard + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/shardTopology/properties/shard/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|shardTopology/shard + if: + type: function + name: isMachineCustom|shardTopology/shard + label: Cpu + watcher: + func: setRequests|cpu|shardTopology/shard + paths: + - schema/properties/spec/properties/shardTopology/properties/shard/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/shardTopology/properties/shard/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|shardTopology/shard + if: + type: function + name: isMachineCustom|shardTopology/shard + label: Memory + watcher: + func: setRequests|memory|shardTopology/shard + paths: + - schema/properties/spec/properties/shardTopology/properties/shard/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/shardTopology/properties/shard/properties/podResources/properties/resources/properties/requests/properties/memory type: input - if: isHorizonsOn - label: - text: Horizons - onChange: updateSuffix - schema: - $ref: schema#/properties/spec/properties/replicaSet/properties/horizons - type: list-input-form - validationRuleObject: - func: isHorizonsValid - if: isEqualToModelPathValue|Replicaset|/spec/mode - schema: - $ref: schema#/properties/spec/properties/replicaSet - type: single-step-form + type: block-layout + label: Shard Nodes + showLabels: true + type: block-layout - elements: + - customClass: mt-10 + label: Replicaset Number + schema: schema/properties/spec/properties/shardTopology/properties/configServer/properties/replicas + type: input + - label: Storage size + schema: schema/properties/spec/properties/shardTopology/properties/configServer/properties/persistence/properties/size + type: input - elements: - - customClass: mt-10 - label: - text: labels.shards - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/shard/properties/shards - type: input - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/shard/properties/replicas + - init: + type: func + value: setMachineToCustom|shardTopology/configServer + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/shardTopology/properties/configServer/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|shardTopology/configServer + if: + type: function + name: isMachineCustom|shardTopology/configServer + label: cpu + watcher: + func: setRequests|cpu|shardTopology/configServer + paths: + - schema/properties/spec/properties/shardTopology/properties/configServer/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/shardTopology/properties/configServer/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/shard/properties/persistence/properties/size + - init: + type: func + value: setLimits|memory|shardTopology/configServer + if: + type: function + name: isMachineCustom|shardTopology/configServer + label: memory + watcher: + func: setRequests|memory|shardTopology/configServer + paths: + - schema/properties/spec/properties/shardTopology/properties/configServer/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/shardTopology/properties/configServer/properties/podResources/properties/resources/properties/requests/properties/memory type: input - - elements: - - computed: setMachineToCustom|shardTopology/shard - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/shard/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|shardTopology/shard - disabled: isMachineNotCustom|shardTopology/shard - if: isMachineCustom|shardTopology/shard - label: - text: labels.cpu - onChange: setRequests|cpu|shardTopology/shard - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/shard/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|shardTopology/shard - disabled: isMachineNotCustom|shardTopology/shard - if: isMachineCustom|shardTopology/shard - label: - text: labels.memory - onChange: setRequests|memory|shardTopology/shard - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/shard/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/shard/properties/podResources - type: single-step-form - label: - text: labels.shardNodes - show_label: true - type: single-step-form + type: block-layout + label: Config Server + showLabels: true + type: block-layout + - elements: + - customClass: mt-10 + label: Replicaset number + schema: schema/properties/spec/properties/shardTopology/properties/mongos/properties/replicas + type: input - elements: - - customClass: mt-10 - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/configServer/properties/replicas + - init: + type: func + value: setMachineToCustom|shardTopology/mongos + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/shardTopology/properties/mongos/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|shardTopology/mongos + if: + type: function + name: isMachineCustom|shardTopology/mongos + label: Cpu + watcher: + func: setRequests|cpu|shardTopology/mongos + paths: + - schema/properties/spec/properties/shardTopology/properties/mongos/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/shardTopology/properties/mongos/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/configServer/properties/persistence/properties/size + - init: + type: func + value: setLimits|memory|shardTopology/mongos + if: + type: function + name: isMachineCustom|shardTopology/mongos + label: Memory + watcher: + func: setRequests|memory|shardTopology/mongos + paths: + - schema/properties/spec/properties/shardTopology/properties/mongos/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/shardTopology/properties/mongos/properties/podResources/properties/resources/properties/requests/properties/memory type: input - - elements: - - computed: setMachineToCustom|shardTopology/configServer - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/configServer/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|shardTopology/configServer - disabled: isMachineNotCustom|shardTopology/configServer - if: isMachineCustom|shardTopology/configServer - label: - text: labels.cpu - onChange: setRequests|cpu|shardTopology/configServer - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/configServer/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|shardTopology/configServer - disabled: isMachineNotCustom|shardTopology/configServer - if: isMachineCustom|shardTopology/configServer - label: - text: labels.memory - onChange: setRequests|memory|shardTopology/configServer - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/configServer/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/configServer/properties/podResources - type: single-step-form - label: - text: labels.configServer - show_label: true - type: single-step-form + type: block-layout + label: mongos + showLabels: true + type: block-layout + if: + type: function + name: isEqualToModelPathValue|Sharded|/spec/mode + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: notEqualToDatabaseMode|Sharded + label: Machine profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage select + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: showStorageSizeField + label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: notEqualToDatabaseMode|Standalone + label: Enable Arbiter? + schema: schema/properties/spec/properties/arbiter/properties/enabled + type: switch + - elements: - elements: - - customClass: mt-10 - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/mongos/properties/replicas + - init: + type: func + value: setMachineToCustom|arbiter + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/arbiter/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|arbiter + if: + type: function + name: isMachineCustom|arbiter + label: cpu + watcher: + func: setRequests|cpu|arbiter + paths: + - schema/properties/spec/properties/arbiter/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/arbiter/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|arbiter + if: + type: function + name: isMachineCustom|arbiter + label: memory + watcher: + func: setRequests|memory|arbiter + paths: + - schema/properties/spec/properties/arbiter/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/arbiter/properties/podResources/properties/resources/properties/requests/properties/memory type: input - - elements: - - computed: setMachineToCustom|shardTopology/mongos - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/mongos/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|shardTopology/mongos - disabled: isMachineNotCustom|shardTopology/mongos - if: isMachineCustom|shardTopology/mongos - label: - text: labels.cpu - onChange: setRequests|cpu|shardTopology/mongos - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/mongos/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|shardTopology/mongos - disabled: isMachineNotCustom|shardTopology/mongos - if: isMachineCustom|shardTopology/mongos - label: - text: labels.memory - onChange: setRequests|memory|shardTopology/mongos - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/mongos/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - schema: - $ref: schema#/properties/spec/properties/shardTopology/properties/mongos/properties/podResources - type: single-step-form - label: - text: labels.mongos - show_label: true - type: single-step-form - if: isEqualToModelPathValue|Sharded|/spec/mode - type: single-step-form + label: '' + type: block-layout + if: + type: function + name: showArbiter + label: Arbiter + showLabels: true + type: block-layout + - if: + type: function + name: notEqualToDatabaseMode|Standalone + label: Enable hidden? + schema: schema/properties/spec/properties/hidden/properties/enabled + type: switch - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine + - customClass: mt-10 + label: Replicas + schema: schema/properties/spec/properties/hidden/properties/replicas + type: input + - label: Persistence Size + schema: schema/properties/spec/properties/hidden/properties/persistence/properties/size + type: input + - init: + type: func + value: setMachineToCustom|hidden + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/hidden/properties/podResources/properties/machine type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + - init: + type: func + value: setLimits|cpu|hidden + if: + type: function + name: isMachineCustom|hidden + label: cpu + watcher: + func: setRequests|cpu|hidden + paths: + - schema/properties/spec/properties/hidden/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/hidden/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|hidden + if: + type: function + name: isMachineCustom|hidden + label: memory + schema: schema/properties/spec/properties/hidden/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: showHidden + label: Hidden + showLabels: true + type: block-layout + - init: + type: func + value: getDefault|pointInTimeRecovery + if: + type: function + name: isToggleOn|pointInTimeRecovery + label: Point in-time Recovery? + schema: temp/recovery + type: switch + - elements: + - label: Namespace + watcher: + func: setPointInTimeRecovery + paths: + - temp/refNamespace + validation: + type: required + schema: temp/refNamespace + type: input + - label: Name + watcher: + func: setPointInTimeRecovery + paths: + - temp/refDBName + validation: + type: required + schema: temp/refDBName type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + - customClass: mt-10 + label: Recovery Timestamp + schema: schema/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp type: input - if: notEqualToDatabaseMode|Sharded - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.select - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + if: + type: function + name: showRecovery + label: Point in-time Recovery + showLabels: true + type: block-layout + - if: + type: function + name: isToggleOn|deployment + label: Deployment + options: + - description: shared + text: Shared + value: Shared + - description: Dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: ClusterTier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: labels.placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default type: select - - if: showStorageSizeField - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size - type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - recovery: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: NodeTopology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options + options: + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - if: notEqualToDatabaseMode|Standalone - label: - text: Enable Arbiter? - schema: - $ref: schema#/properties/spec/properties/arbiter/properties/enabled - type: switch - - elements: - - elements: - - computed: setMachineToCustom|arbiter - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/arbiter/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|arbiter - disabled: isMachineNotCustom|arbiter - if: isMachineCustom|arbiter - label: - text: labels.cpu - onChange: setRequests|cpu|arbiter - schema: - $ref: schema#/properties/spec/properties/arbiter/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|arbiter - disabled: isMachineNotCustom|arbiter - if: isMachineCustom|arbiter - label: - text: labels.memory - onChange: setRequests|memory|arbiter - schema: - $ref: schema#/properties/spec/properties/arbiter/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - schema: - $ref: schema#/properties/spec/properties/arbiter/properties/podResources - type: single-step-form - if: showArbiter - label: - text: Arbiter - schema: - $ref: schema#/properties/spec/properties/arbiter - show_label: true - type: single-step-form - - if: notEqualToDatabaseMode|Standalone - label: - text: Enable hidden? - schema: - $ref: schema#/properties/spec/properties/hidden/properties/enabled + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - disable: showArchiverAlert + label: Enable Archiver? + watcher: + func: onArchiverChange + paths: + - schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default + schema: schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch - - elements: - - customClass: mt-10 - label: - text: Replicas - schema: - $ref: schema#/properties/spec/properties/hidden/properties/replicas - type: input - - label: - text: Persistence Size - schema: - $ref: schema#/properties/spec/properties/hidden/properties/persistence/properties/size - type: input - - computed: setMachineToCustom|hidden - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/hidden/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|hidden - disabled: isMachineNotCustom|hidden - if: isMachineCustom|hidden - label: - text: labels.cpu - onChange: setRequests|cpu|hidden - schema: - $ref: schema#/properties/spec/properties/hidden/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|hidden - disabled: isMachineNotCustom|hidden - if: isMachineCustom|hidden - label: - text: labels.memory - schema: - $ref: schema#/properties/spec/properties/hidden/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - if: showHidden - label: - text: Hidden - schema: - $ref: schema#/properties/spec/properties/hidden/properties/podResources - show_label: true - type: single-step-form - - computed: getDefault|pointInTimeRecovery - if: isToggleOn|pointInTimeRecovery - label: - text: Point in-time Recovery? - schema: - $ref: discriminator#/recovery + - if: + type: function + name: showArchiverAlert + label: The selected StorageClass does not support Archiver + type: warning + if: + type: function + name: showArchiver + type: block-layout + - elements: + - init: + type: func + value: checkHostnameOrIP + if: + type: function + name: isToggleOn|tls + label: Enable TLS? + watcher: + func: checkHostnameOrIP + paths: + - schema/properties/spec/properties/admin/properties/tls/properties/default + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - discriminator: - refDBName: - type: string - refNamespace: - type: string - elements: - - label: - text: Namespace - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refNamespace - type: input - - label: - text: Name - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refDBName - type: input - - customClass: mt-10 - label: - text: Recovery Timestamp - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp - type: input - if: showRecovery - label: - text: Point in-time Recovery - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver - show_label: true - type: single-step-form - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + type: block-layout + - elements: + - init: + type: func + value: checkHostnameOrIP + if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + watcher: + func: checkHostnameOrIP + paths: + - schema/properties/spec/properties/admin/properties/expose/properties/default + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - disabled: showArchiverAlert - label: - text: Enable Archiver? - onChange: onArchiverChange - schema: - $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default - type: switch - - alertInfo: - show: true - type: neutral - if: showArchiverAlert - label: - text: The selected StorageClass does not support Archiver - type: label-element - if: showArchiver - type: single-step-form - - elements: - - computed: checkHostnameOrIP - if: isToggleOn|tls - label: - text: Enable TLS? - onChange: checkHostnameOrIP - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - elements: - - computed: checkHostnameOrIP - if: isToggleOn|expose - label: - text: Expose via Gateway? - onChange: checkHostnameOrIP - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label -type: multi-step-form + # title: steps.0.label +type: multi-step-form \ No newline at end of file diff --git a/charts/kubedbcom-mongodb-editor-options/ui/functions.js b/charts/kubedbcom-mongodb-editor-options/ui/functions.js index b12b2a9522..8c79ec6de1 100644 --- a/charts/kubedbcom-mongodb-editor-options/ui/functions.js +++ b/charts/kubedbcom-mongodb-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -319,1260 +321,1283 @@ const modeDetails = { }, } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] - } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('enableHorizons', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('recovery', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('refDBName', '') + setDiscriminatorValue('refNamespace', '') + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(modelPathValue) -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Standalone', 'Replicaset'] + return validType.includes(modelPathValue) + } -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - const projects = resp?.data?.status?.projects - if (projects) { - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - namespaces = projectsNamespace - } else { - namespaces = resp?.data?.status?.namespaces || [] + ) + const projects = resp?.data?.status?.projects + if (projects) { + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + namespaces = projectsNamespace + } else { + namespaces = resp?.data?.status?.namespaces || [] + } + return namespaces + } catch (e) { + console.log(e) + return [] } - return namespaces - } catch (e) { - console.log(e) - return [] } -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } } -} -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: comparePath, - value: memory, + path: commitPath, + value: val, force: true, }) - return memory - } else { + } + + function setMachineToCustom(type) { + let path = '' + if (type) path = `/spec/${type}/podResources/machine` + else path = '/spec/admin/machineProfiles/default' + const machine = getValue(model, path) + return machine || 'custom' + } + + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true } -} - -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + if (val === 'capz' && ifDedicated()) return true } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} - -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} - -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} - -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] - } + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb]`, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, commit, getValue, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb]`, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } } - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} - -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} - -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} - -function showRecovery({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/recovery') - const isRecoveryOn = getValue(discriminator, '/recovery') || '' - return isRecoveryOn -} - -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} - -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} - -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} - -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') - } -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) -function returnFalse() { - return false -} + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -let namespaces = [] -let hostName = '' -let ip = '' -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const gatewayinfosurl = `/clusters/${owner}/${cluster}/proxy/meta.k8s.appscode.com/v1alpha1/gatewayinfos/${namespace}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } + } - const gatewayinfosResp = await axios.get(gatewayinfosurl) - hostName = gatewayinfosResp.data?.spec?.hostName - ip = gatewayinfosResp.data?.spec?.ip - } catch (e) { - console.log(e) + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } - if (!getValue(model, `/spec/admin/databases/MongoDB/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/MongoDB/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/MongoDB/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function showRecovery() { + // watchDependency('discriminator#/recovery') + const isRecoveryOn = getValue(discriminator, '/recovery') || '' + return isRecoveryOn + } + + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone } - if (!features.includes('tls')) { + function clearArbiterHidden() { commit('wizard/model$update', { - path: '/spec/admin/tls/default', + path: `/spec/arbiter/enabled`, value: false, force: true, }) - } - if (!features.includes('binding')) { + commit('wizard/model$update', { - path: '/spec/admin/expose/default', + path: `/spec/hidden/enabled`, value: false, force: true, }) } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) + + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - namespaces = getNamespaces({ axios, storeGet }) - setDiscriminatorValue('/bundleApiLoaded', true) -} -function fetchNamespaces({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return namespaces -} + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + function returnFalse() { + return false } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let namespaces = [] + let hostName = '' + let ip = '' + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const gatewayinfosurl = `/clusters/${owner}/${cluster}/proxy/meta.k8s.appscode.com/v1alpha1/gatewayinfos/${namespace}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + + const gatewayinfosResp = await axios.get(gatewayinfosurl) + hostName = gatewayinfosResp.data?.spec?.hostName + ip = gatewayinfosResp.data?.spec?.ip + } catch (e) { + console.log(e) + } + commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} -let archiverMap = [] -let archiverCalled = false - -function getAdminOptions({ getValue, model, watchDependency, axios, storeGet, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!getValue(model, `/spec/admin/databases/MongoDB/mode/toggle`)) { + let defMode = getDefault('databases/MongoDB/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/MongoDB/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - if (type === 'storageClasses' && !archiverCalled) { - getArchiverName({ axios, storeGet }) + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } + namespaces = getNamespaces() + setDiscriminatorValue('/bundleApiLoaded', true) } - const options = getValue(model, `/spec/admin/${type}/available`) || [] - - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + function fetchNamespaces() { + // watchDependency('discriminator#/bundleApiLoaded') + return namespaces } - return options -} -function showArchiver({ watchDependency, getValue, model, commit }) { - watchDependency('model#/spec/mode') - const dbmode = getValue(model, '/spec/mode') + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } - if (dbmode === 'Standalone') { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - return false - } - return checkIfFeatureOn({ getValue, model }, 'archiver') -} + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } -async function getArchiverName({ axios, storeGet }) { - 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) + return returnArray } -} -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) + let archiverMap = [] + let archiverCalled = false - if (isArchiverOn && found?.annotation) - commit('wizard/model$update', { - path: '/spec/archiverName', - value: found.annotation, - force: true, - }) - else - commit('wizard/model$update', { - path: '/spec/archiverName', - value: '', - force: true, - }) -} + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') -function showArchiverAlert({ watchDependency, model, getValue, commit }) { - watchDependency('model#/spec/admin/storageClasses/default') + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName() + } - const mode = getValue(model, '/spec/mode') - if (mode === 'Standalone') return false + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const stClass = getValue(model, '/spec/admin/storageClasses/default') - const found = archiverMap.find((item) => item.storageClass === stClass) - const show = !found?.annotation + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } - // 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, - }) - else onArchiverChange({ model, getValue, commit }) + function showArchiver() { + // watchDependency('model#/spec/mode') + const dbmode = getValue(model, '/spec/mode') - return show -} + if (dbmode === 'Standalone') { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return false + } + return checkIfFeatureOn('archiver') + } -async function getRecoveryNames({ getValue, model, watchDependency, storeGet, axios }, type) { - watchDependency(`model#/spec/init/archiver/${type}/namespace`) - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` - if (type === 'encryptionSecret') - url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - const options = [] - if (namespace) { + async function getArchiverName() { 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) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) + + 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) } } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') + function onArchiverChange() { + 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 (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && val + if (isArchiverOn && found?.annotation) + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) + else + commit('wizard/model$update', { + path: '/spec/archiverName', + value: '', + force: true, + }) } -} -function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + function showArchiverAlert() { + // watchDependency('model#/spec/admin/storageClasses/default') + + 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/deployment/default', - value: 'Shared', + path: '/spec/admin/archiver/enable/default', + value: false, force: true, }) + else onArchiverChange() + + return show + } + + async function getRecoveryNames(type) { + // watchDependency(`model#/spec/init/archiver/${type}/namespace`) + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` + if (type === 'encryptionSecret') + url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + const options = [] + if (namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + return options + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } + + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -async function checkHostnameOrIP({ commit, model, getValue }) { - const tls = getValue(model, '/spec/admin/tls/default') - const expose = getValue(model, '/spec/admin/expose/default') - if (tls && expose) { - if (hostName) { + function checkHostnameOrIP() { + const tls = getValue(model, '/spec/admin/tls/default') + const expose = getValue(model, '/spec/admin/expose/default') + if (tls && expose) { + if (hostName) { + commit('wizard/model$update', { + path: '/spec/hostName', + value: hostName, + force: true, + }) + } else { + commit('wizard/model$update', { + path: '/spec/ip', + value: ip, + force: true, + }) + } + } else { commit('wizard/model$update', { path: '/spec/hostName', - value: hostName, + value: '', force: true, }) - } else { commit('wizard/model$update', { path: '/spec/ip', - value: ip, + value: '', force: true, }) } - } else { - commit('wizard/model$update', { - path: '/spec/hostName', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/ip', - value: '', - force: true, - }) } -} - -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} - -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} -function convertToLocal(input) { - const date = new Date(input) + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } - if (isNaN(date.getTime())) { - return null + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val } - return date.toString() -} + function convertToLocal(input) { + const date = new Date(input) -function getComponentLogStats(snapshot) { - if (!snapshot || !snapshot.status || !snapshot.status.components) { - return null + if (isNaN(date.getTime())) { + return null + } + + return date.toString() } - const components = snapshot.status.components - const appKind = snapshot.spec?.appRef?.kind + function getComponentLogStats(snapshot) { + if (!snapshot || !snapshot.status || !snapshot.status.components) { + return null + } + + const components = snapshot.status.components + const appKind = snapshot.spec?.appRef?.kind - if (appKind === 'MongoDB') { - for (const [key, value] of Object.entries(components)) { - if (key.endsWith('0') && value.logStats) { - return value.logStats + if (appKind === 'MongoDB') { + for (const [key, value] of Object.entries(components)) { + if (key.endsWith('0') && value.logStats) { + return value.logStats + } } } - } - if (components['wal'] && components['wal'].logStats) { - return components['wal'].logStats - } + if (components['wal'] && components['wal'].logStats) { + return components['wal'].logStats + } - return null -} + return null + } -async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const refNamespace = getValue(discriminator, '/refNamespace') - const refDBName = getValue(discriminator, '/refDBName') + async function setPointInTimeRecovery() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const refNamespace = getValue(discriminator, '/refNamespace') + const refDBName = getValue(discriminator, '/refDBName') - try { - const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` - const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` - const repositoriesResp = await axios.get(repositoriesUrl) - const snapshotsResp = await axios.get(snapshotsUrl) + try { + const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` + const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` + const repositoriesResp = await axios.get(repositoriesUrl) + const snapshotsResp = await axios.get(snapshotsUrl) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/name`, - value: repositoriesResp.data?.spec.encryptionSecret.name, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/namespace`, - value: repositoriesResp.data?.spec.encryptionSecret.namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/name`, - value: `${refDBName}-full`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/name`, - value: `${refDBName}-manifest`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/name`, + value: repositoriesResp.data?.spec.encryptionSecret.name, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/namespace`, + value: repositoriesResp.data?.spec.encryptionSecret.namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/name`, + value: `${refDBName}-full`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/name`, + value: `${refDBName}-manifest`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) - const resp = getComponentLogStats(snapshotsResp.data) + const resp = getComponentLogStats(snapshotsResp.data) - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: convertToLocal(resp?.end), - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: convertToLocal(resp?.start), - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: convertToLocal(resp?.end), - force: true, - }) - } catch (e) { - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: '', - force: true, - }) - console.log(e) + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: convertToLocal(resp?.end), + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: convertToLocal(resp?.start), + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: convertToLocal(resp?.end), + force: true, + }) + } catch (e) { + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: '', + force: true, + }) + console.log(e) + } } -} -// horizon stuffs -function isTlsOn({ getValue, model, watchDependency }) { - watchDependency('model#/spec/admin/tls/default') - watchDependency('model#/spec/admin/expose/default') + // horizon stuffs + function isTlsOn() { + // watchDependency('model#/spec/admin/tls/default') + // watchDependency('model#/spec/admin/expose/default') - const tls = getValue(model, '/spec/admin/tls/default') - const expose = getValue(model, '/spec/admin/expose/default') - return tls && expose -} + const tls = getValue(model, '/spec/admin/tls/default') + const expose = getValue(model, '/spec/admin/expose/default') + return tls && expose + } -function isHorizonsOn({ getValue, discriminator, watchDependency }) { - watchDependency('discriminator#/enableHorizons') - const horizon = getValue(discriminator, '/enableHorizons') - return horizon -} + function isHorizonsOn() { + // watchDependency('discriminator#/enableHorizons') + const horizon = getValue(discriminator, '/enableHorizons') + return horizon + } -function onHorizonsChange({ getValue, commit, discriminator }) { - const val = getValue(discriminator, '/enableHorizons') - if (!val) { - commit({ - path: '/spec/replicaSet/horizons', - value: [], - force: true, - }) + function onHorizonsChange() { + const val = getValue(discriminator, '/enableHorizons') + if (!val) { + commit({ + path: '/spec/replicaSet/horizons', + value: [], + force: true, + }) + } } -} -function updateSuffix({ getValue, model, commit, watchDependency, discriminator }) { - const horizons = getValue(model, '/spec/replicaSet/horizons') || [] - const length = horizons?.length || 0 + function updateSuffix() { + const horizons = getValue(model, '/spec/replicaSet/horizons') || [] + const length = horizons?.length || 0 - const replicas = getValue(model, '/spec/replicaSet/replicas') || 0 + const replicas = getValue(model, '/spec/replicaSet/replicas') || 0 - if (replicas !== length && isHorizonsOn({ getValue, discriminator, watchDependency })) - commit('wizard/model$update', { - path: '/spec/hostName', - value: '', - force: true, - }) - else { - const common = getCommonPostfix(horizons) - if (common) + if (replicas !== length && isHorizonsOn()) commit('wizard/model$update', { path: '/spec/hostName', - value: common, + value: '', force: true, }) + else { + const common = getCommonPostfix(horizons) + if (common) + commit('wizard/model$update', { + path: '/spec/hostName', + value: common, + force: true, + }) + } } -} -function getCommonPostfix(strings) { - if (strings.length === 0) return '' + function getCommonPostfix(strings) { + if (strings.length === 0) return '' - const reversedParts = strings.map((str) => str.split('.').reverse()) - const first = reversedParts[0] + const reversedParts = strings.map((str) => str.split('.').reverse()) + const first = reversedParts[0] - const commonParts = [] + const commonParts = [] - for (let i = 0; i < first.length; i++) { - const part = first[i] - if (reversedParts.every((parts) => parts[i] === part)) { - commonParts.push(part) - } else { - break + for (let i = 0; i < first.length; i++) { + const part = first[i] + if (reversedParts.every((parts) => parts[i] === part)) { + commonParts.push(part) + } else { + break + } } - } - return commonParts.length ? commonParts.reverse().join('.') : '' -} + return commonParts.length ? commonParts.reverse().join('.') : '' + } -function isHorizonsValid({ getValue, model, watchDependency }) { - watchDependency('model#/spec/replicaSet/replicas') - const horizons = getValue(model, '/spec/replicaSet/horizons') || [] - const length = horizons?.length || 0 - const replicas = getValue(model, '/spec/replicaSet/replicas') || 0 + function isHorizonsValid() { + // watchDependency('model#/spec/replicaSet/replicas') + const horizons = getValue(model, '/spec/replicaSet/horizons') || [] + const length = horizons?.length || 0 + const replicas = getValue(model, '/spec/replicaSet/replicas') || 0 - if (length !== replicas) return `Horizons count need to be equal to ${replicas}` + if (length !== replicas) return `Horizons count need to be equal to ${replicas}` - const common = getCommonPostfix(horizons) - if (!common) return 'Horizons must have a common dot (.) seperated suffix' - return true -} + const common = getCommonPostfix(horizons) + if (!common) return 'Horizons must have a common dot (.) seperated suffix' + return true + } -return { - onReferSecretChange, - showReferSecretSwitch, - getDefaultValue, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - setPointInTimeRecovery, - checkHostnameOrIP, - isRancherManaged, - getRecoveryNames, - fetchNamespaces, - showRecovery, - showAdditionalSettings, - returnFalse, - initBundle, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showStorageSizeField, - getNamespaces, - onCreateAuthSecretChange, - isMachineNotCustom, - isMachineCustom, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - updateAlertValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - showArbiter, - showHidden, - notEqualToDatabaseMode, - clearArbiterHidden, - isConfigDatabaseOn, - clearConfiguration, - isToggleOn, - getAdminOptions, - onBackupSwitch, - showAlerts, - showIssuer, - setMonitoring, - getNodeTopology, - filterNodeTopology, - onAuthChange, - setBackup, - getDefault, - onArchiverChange, - showArchiverAlert, - showArchiver, - isTlsOn, - isHorizonsOn, - updateSuffix, - onHorizonsChange, - isHorizonsValid, + return { + onReferSecretChange, + showReferSecretSwitch, + getDefaultValue, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + setPointInTimeRecovery, + checkHostnameOrIP, + isRancherManaged, + getRecoveryNames, + fetchNamespaces, + showRecovery, + showAdditionalSettings, + returnFalse, + initBundle, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + showStorageSizeField, + getNamespaces, + onCreateAuthSecretChange, + isMachineNotCustom, + isMachineCustom, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAlertValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + showArbiter, + showHidden, + notEqualToDatabaseMode, + clearArbiterHidden, + isConfigDatabaseOn, + clearConfiguration, + isToggleOn, + getAdminOptions, + onBackupSwitch, + showAlerts, + showIssuer, + setMonitoring, + getNodeTopology, + filterNodeTopology, + onAuthChange, + setBackup, + getDefault, + onArchiverChange, + showArchiverAlert, + showArchiver, + isTlsOn, + isHorizonsOn, + updateSuffix, + onHorizonsChange, + isHorizonsValid, + } } diff --git a/charts/kubedbcom-mongodb-editor/ui/edit-ui.yaml b/charts/kubedbcom-mongodb-editor/ui/edit-ui.yaml index ced013c4cd..7b93992f60 100644 --- a/charts/kubedbcom-mongodb-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-mongodb-editor/ui/edit-ui.yaml @@ -1,2519 +1,1505 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - fetch: getResources|core|v1|namespaces - label: - text: labels.namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - disableUnselect: true - disabled: true - fetch: getMongoDbVersions|catalog.kubedb.com|v1alpha1|mongodbversions - label: - text: labels.database.version - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/version - type: select - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/deletionPolicy - type: radio - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/authSecret/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - elements: - - alias: reusable_alert - chart: - name: uibytebuildersdev-component-alert - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/form/properties/alert - type: reusable-element - type: single-step-form - id: alert - title: labels.alert -- form: +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - discriminator: - activeDatabaseMode: - default: Standalone - type: string - elements: - - if: isNotStandaloneMode - label: - text: labels.to_update_replicas - type: label-element - - customClass: mb-20 - if: isNotStandaloneMode - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mongodbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=HorizontalScaling - - computed: setDatabaseMode - disabled: true - hasDescription: true - label: - text: labels.database.mode - onChange: deleteDatabaseModePath + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - description: options.database.mode.Standalone.description - text: options.database.mode.Standalone.label - value: Standalone - - description: options.database.mode.Replicaset.description - text: options.database.mode.Replicaset.label - value: Replicaset - - description: options.database.mode.Sharded.description - text: options.database.mode.Sharded.label - value: Sharded - schema: - $ref: discriminator#/activeDatabaseMode - type: radio - - disabled: true + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - label: - text: labels.replicaset.name - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/replicaSet/properties/name - type: input - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/replicas - type: input - if: isEqualToDatabaseMode|Replicaset - type: single-step-form - - disabled: true - elements: - - fetch: getStorageClassNames|common - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/storage/properties/storageClassName - type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/storage/properties/resources/properties/requests/properties/storage - type: input - if: showCommonStorageClassAndSizeField - type: single-step-form - - disabled: true - elements: - - elements: - - fetch: getStorageClassNames|shard - label: - text: labels.storage.class - onChange: setStorageClass - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/shard/properties/storage/properties/storageClassName - type: select - - label: - text: labels.shardNodes - type: label-element - - elements: - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/shard/properties/storage/properties/resources/properties/requests/properties/storage - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/shard/properties/storage/properties/resources/properties/requests - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/shard/properties/storage/properties/resources - type: single-step-form - type: single-step-form - - label: - text: labels.shards - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/shard/properties/shards - type: input - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/shard/properties/replicas - type: input - - label: - text: labels.configServer - type: label-element - - elements: - - elements: - - elements: - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/configServer/properties/storage/properties/resources/properties/requests/properties/storage - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/configServer/properties/storage/properties/resources/properties/requests - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/configServer/properties/storage/properties/resources - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/configServer/properties/storage - type: single-step-form - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/configServer/properties/replicas - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/configServer - type: single-step-form - - label: - text: labels.mongos - type: label-element - - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/mongos/properties/replicas - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/mongos - type: single-step-form - if: isEqualToDatabaseMode|Sharded - type: single-step-form - type: single-step-form - type: single-step-form - id: topology - title: steps.1.label -- form: - discriminator: - configureTLS: - default: true - type: boolean + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true + options: + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig + elements: + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + + - type: single-step-form + id: monitoring elements: - - label: - text: labels.to_update_tls - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mongodbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=ReconfigureTLS - - computed: isValueExistInModel|/resources/kubedbComMongoDB/spec/tls - disabled: true - label: - text: labels.enable_tls - onChange: onTlsConfigureChange - schema: - $ref: discriminator#/configureTLS - type: switch - - disabled: true + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComMongoDB/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - computed: setClusterAuthMode - label: - text: labels.cluster_auth_mode - options: - - text: x509 - value: x509 - - text: sendX509 - value: sendX509 - - text: keyFile - value: keyFile - - text: sendKeyFile - value: sendKeyFile - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/clusterAuthMode - type: radio - - computed: setSSLMode - label: - text: labels.ssl_mode - options: - - text: requireSSL - value: requireSSL - - text: preferSSL - value: preferSSL - - text: allowSSL - value: allowSSL - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/sslMode - type: radio - - elements: - - computed: setApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - title: steps.2.label -- form: - elements: - - disabled: disableInitializationSection - discriminator: - prePopulateDatabase: - type: string - elements: - - computed: initPrePopulateDatabase - label: - text: labels.prePopulateDatabase - onChange: onPrePopulateDatabaseChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/prePopulateDatabase - type: radio - - discriminator: - dataSource: - type: string - elements: - - computed: initDataSource - label: - text: labels.dataSource - onChange: onDataSourceChange - options: - - text: options.dataSource.script.text - value: script - - text: options.dataSource.stashBackup.text - value: stashBackup - schema: - $ref: discriminator#/properties/dataSource - type: select - - discriminator: - sourceVolumeType: - type: string + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMongoDB/spec/monitor/agent elements: - - label: - text: labels.script.path - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/init/properties/script/properties/scriptPath - type: input - - label: - text: labels.script.volume - type: label-element - - computed: initVolumeType - label: - text: labels.script.volumeType - onChange: onVolumeTypeChange - options: - - text: options.scriptSourceVolumeType.configMap.text - value: configMap - - text: options.scriptSourceVolumeType.secret.text - value: secret - schema: - $ref: discriminator#/properties/sourceVolumeType - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|configmaps - if: showConfigMapOrSecretName|configMap - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/init/properties/script/properties/configMap/properties/name - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|secrets - if: showConfigMapOrSecretName|secret - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/init/properties/script/properties/secret/properties/secretName - type: select - if: showScriptOrStashForm|script - type: single-step-form - - elements: - - label: - text: labels.restoreSession.snapshot - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/rules/properties/0/properties/snapshots/properties/0 - type: input - - discriminator: - repositoryChoise: - type: string + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMongoDB/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: labels.repositories.title - type: label-element - - computed: setInitialRestoreSessionRepo - onChange: onInitRepositoryChoiseChange - options: - - text: options.createOrSelect.select.text - value: select - - text: options.createOrSelect.create.text - value: create - schema: - $ref: discriminator#/properties/repositoryChoise - type: radio - - allowUserDefinedOption: true - fetch: resourceNames|stash.appscode.com|v1alpha1|repositories - if: showRepositorySelectOrCreate|select - label: - text: labels.repositories.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/repository/properties/name - type: select - - alias: repository_create_init - chart: - name: uibytebuildersdev-component-repository-create - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRepositorySelectOrCreate|create - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRepository_init_repo/properties/spec/properties/backend - type: reusable-element - type: single-step-form - - if: returnFalse - label: - text: labels.backupConfiguration.targetReference.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/target/properties/ref/properties/name - type: input - - discriminator: - customizeRestoreJobRuntimeSettings: - type: string + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse elements: - - computed: initCustomizeRestoreJobRuntimeSettings - label: - isSubsection: true - text: labels.runtimeSettings.choise - onChange: onCustomizeRestoreJobRuntimeSettingsChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/customizeRestoreJobRuntimeSettings - type: radio - - alias: runtime_settings_init - chart: - name: uibytebuildersdev-component-runtime-settings - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRuntimeForm|yes - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/runtimeSettings - type: reusable-element - type: single-step-form - if: showScriptOrStashForm|stashBackup - type: single-step-form - - if: returnFalse - label: - text: labels.waitForInitialRestore - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/init/properties/waitForInitialRestore - type: switch - if: showInitializationForm - type: single-step-form - type: single-step-form - type: single-step-form - id: initialization - title: steps.3.label -- form: - discriminator: - repoInitialSelectionStatus: - type: string - scheduleBackup: - default: "yes" - type: string - elements: - - computed: initScheduleBackupForEdit - if: showScheduleBackup - label: - text: labels.backup.title - onChange: onScheduleBackupChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/scheduleBackup - type: radio - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean - elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string - elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean - elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean - elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - if: showBackupForm - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.4.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComMongoDB/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMongoDB/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMongoDB/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + loader: setMetadata + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMongoDB/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMongoDB/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - - computed: setMetadata - if: returnFalse - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - elements: - - elements: - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - type: single-step-form - id: pod-template - if: isNotShardModeSelected - title: steps.6.label -- form: - steps: - - form: - elements: - - elements: - - alias: pod_template_shard - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/shard/properties/podTemplate - type: reusable-element - type: single-step-form - type: single-step-form - id: pod-template-shard - title: labels.shard - - form: - elements: - - elements: - - alias: pod_template_configserver - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/configServer/properties/podTemplate - type: reusable-element - type: single-step-form - type: single-step-form - id: pod-template-config-server - title: labels.configServer - - form: - elements: - - elements: - - alias: pod_template_mongos - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/mongos/properties/podTemplate - type: reusable-element - type: single-step-form - type: single-step-form - id: pod-template-mongos - title: labels.mongos - type: multi-step-form - id: pod-template-sharded-topology - if: isShardModeSelected - title: steps.7.label -- form: + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.8.label -- form: - elements: - - label: - text: labels.to_update_config - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mongodbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=Reconfigure - - disabled: true + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - discriminator: - configurationSource: - default: use-existing-config - type: string - elements: - - onChange: onConfigurationSourceChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/configurationSource - type: radio - - allowUserDefinedOption: true - fetch: getSecrets - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/configSecret/properties/name - type: select - if: isNotShardModeSelected - type: single-step-form - - discriminator: - configurationSourceConfigServer: - default: use-existing-config - type: string - configurationSourceMongos: - default: use-existing-config - type: string - configurationSourceShard: - default: use-existing-config - type: string - elements: - - customClass: mb-10 - label: - text: labels.shardNodes - type: label-element - - computed: setConfigurationSourceShard - label: - text: labels.custom_config - onChange: onConfigurationSourceShardChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - - text: options.configuration_source.same_as_config_server.label - value: same-as-configserver-config-secret - - text: options.configuration_source.same_as_mongos.label - value: same-as-mongos-config-secret - schema: - $ref: discriminator#/configurationSourceShard - type: select - - allowUserDefinedOption: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSourceShard - label: - text: labels.config_secret - onChange: onConfigSecretModelChange|shard|use-existing-config - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/shard/properties/configSecret/properties/name - type: select - - customClass: mb-10 - label: - text: labels.configServerNodes - type: label-element - - computed: setConfigurationSourceConfigServer - label: - text: labels.custom_config - onChange: onConfigurationSourceConfigServerChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - - text: options.configuration_source.same_as_shard.label - value: same-as-shard-config-secret - - text: options.configuration_source.same_as_mongos.label - value: same-as-mongos-config-secret - schema: - $ref: discriminator#/configurationSourceConfigServer - type: select - - allowUserDefinedOption: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSourceConfigServer - label: - text: labels.config_secret - onChange: onConfigSecretModelChange|configserver|use-existing-config - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/configServer/properties/configSecret/properties/name - type: select - - customClass: mb-10 - label: - text: labels.mongosNodes - type: label-element - - computed: setConfigurationSourceMongos - label: - text: labels.custom_config - onChange: onConfigurationSourceMongosChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - - text: options.configuration_source.same_as_shard.label - value: same-as-shard-config-secret - - text: options.configuration_source.same_as_config_server.label - value: same-as-configserver-config-secret - schema: - $ref: discriminator#/configurationSourceMongos - type: select - - allowUserDefinedOption: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSourceMongos - label: - text: labels.config_secret - onChange: onConfigSecretModelChange|mongos|use-existing-config - schema: - $ref: schema#/properties/resources/properties/kubedbComMongoDB/properties/spec/properties/shardTopology/properties/mongos/properties/configSecret/properties/name - type: select - if: isShardModeSelected - type: single-step-form - type: single-step-form - type: single-step-form - id: custom-config - title: steps.9.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + # standalone mode + - type: block-layout + label: Standalone + if: + type: function + name: mongoTypeEqualsTo|standalone|compute + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/standalone/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: select + label: Min Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-standalone-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|standalone|min + loader: + name: getMachines|standalone|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-standalone-max + watcher: + func: onMachineChange|standalone + paths: + - temp/properties/allowedMachine-standalone-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed/properties/memory + - type: select + label: Max Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-standalone-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|standalone|max + loader: + name: getMachines|standalone|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-standalone-min + watcher: + func: onMachineChange|standalone + paths: + - temp/properties/allowedMachine-standalone-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|compute/standalone + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/inMemoryStorage + elements: + - type: threshold-input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: threshold-input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/inMemoryStorage/properties/usageThresholdPercentage + # replicaset mode + - type: block-layout + label: ReplicaSet + if: + type: function + name: mongoTypeEqualsTo|replicaSet|compute + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/replicaSet/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: select + label: Min Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-replicaSet-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|replicaSet|min + loader: + name: getMachines|replicaSet|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-replicaSet-max + watcher: + func: onMachineChange|replicaSet + paths: + - temp/properties/allowedMachine-replicaSet-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/minAllowed/properties/cpu + - type: input + label: memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/minAllowed/properties/memory + - type: select + label: Max Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-replicaSet-max + if: + type: function + name: hasAnnotations + loader: + name: getMachines|replicaSet|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-replicaSet-min + init: + type: func + value: setAllowedMachine|replicaSet|max + watcher: + func: onMachineChange|replicaSet + paths: + - temp/properties/allowedMachine-replicaSet-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/maxAllowed/properties/cpu + - type: input + label: memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|compute/replicaSet + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/inMemoryStorage + elements: + - type: input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/inMemoryStorage/properties/usageThresholdPercentage + # type sharded + - type: block-layout + showLabels: false + if: + type: function + name: mongoTypeEqualsTo|sharded|compute + elements: + - type: block-layout + label: Shard + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/shard/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: select + label: Min Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-shard-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|shard|min + loader: + name: getMachines|shard|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-shard-max + watcher: + func: onMachineChange|shard + paths: + - temp/properties/allowedMachine-shard-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/minAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/minAllowed/properties/memory + - type: select + label: Max Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-shard-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|shard|max + loader: + name: getMachines|shard|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-shard-min + watcher: + func: onMachineChange|shard + paths: + - temp/properties/allowedMachine-shard-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/maxAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|compute/shard + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/inMemoryStorage + elements: + - type: input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/inMemoryStorage/properties/usageThresholdPercentage + + - type: block-layout + label: Config Server + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/configServer/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: select + label: Min Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-configServer-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|configServer|min + loader: + name: getMachines|configServer|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-configServer-max + watcher: + func: onMachineChange|configServer + paths: + - temp/properties/allowedMachine-configServer-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/minAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/minAllowed/properties/memory + - type: select + label: Max Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-configServer-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|configServer|max + loader: + name: getMachines|configServer|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-configServer-min + watcher: + func: onMachineChange|configServer + paths: + - temp/properties/allowedMachine-configServer-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/maxAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|compute/configServer + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/inMemoryStorage + elements: + - type: input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/inMemoryStorage/properties/usageThresholdPercentage + - type: block-layout + label: Arbiter + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/arbiter/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/resourceDiffPercentage + - type: block-layout + label: Min Allowed + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/minAllowed + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/minAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/minAllowed/properties/memory + + - type: block-layout + label: Max Allowed + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/maxAllowed + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/maxAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|compute/arbiter + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/inMemoryStorage + elements: + - type: input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/inMemoryStorage/properties/usageThresholdPercentage + - type: block-layout + label: Hidden + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/hidden/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/resourceDiffPercentage + - type: block-layout + label: Min Allowed + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/minAllowed + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/minAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/minAllowed/properties/memory + - type: block-layout + label: Max Allowed + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/maxAllowed + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/maxAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|compute/hidden + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/inMemoryStorage + elements: + - type: input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/inMemoryStorage/properties/usageThresholdPercentage + - type: block-layout + label: Mongos + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/mongos/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/podLifeTimeThreshold + - type: input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: select + label: Min Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-mongos-min + if: + type: function + name: hasAnnotations + loader: + name: getMachines|mongos|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-mongos-max + init: + type: func + value: setAllowedMachine|mongos|min + watcher: + func: onMachineChange|mongos + paths: + - temp/properties/allowedMachine-mongos-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/minAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/minAllowed/properties/memory + - type: select + label: Max Allowed Profile + disableUnselect: true + schema: temp/properties/allowedMachine-mongos-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|mongos|max + loader: + name: getMachines|mongos|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-mongos-min + watcher: + func: onMachineChange|mongos + paths: + - temp/properties/allowedMachine-mongos-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/maxAllowed/properties/cpu + - type: input + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|compute/mongos + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/inMemoryStorage + elements: + - type: input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/inMemoryStorage/properties/usageThresholdPercentage + - type: block-layout + label: NodeTopology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: input + label: Scale Up DiffPercentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: input + label: Scale Down DiffPercentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: block-layout + label: Readiness Criteria + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria + elements: + - type: threshold-input + label: Objects Count Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria/properties/objectsCountDiffPercentage + - type: input + label: Oplog Max Lag Seconds + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria/properties/oplogMaxLagSeconds + - type: select + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + options: + - text: 5 minutes + value: 5m0s + - text: 10 minutes + value: 10m0s + - text: 30 minutes + value: 30m0s + - text: 1 hour + value: 1h0m + - text: 2 hours + value: 2h0m + - text: 5 hours + value: 5h0m + - text: 10 hours + value: 10h0m + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - type: input - - discriminator: - topologyMachines: - default: [] - type: array + - type: block-layout + showLabels: false elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/standalone/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/podLifeTimeThreshold - type: input - - label: - text: Resource DiffPercentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-standalone-max: - type: strin - allowedMachine-standalone-min: - type: string + # standalone mode + - type: block-layout + label: Standalone + if: + type: function + name: mongoTypeEqualsTo|standalone|storage + showLabels: true elements: - - computed: setAllowedMachine|standalone|min - disableUnselect: true - fetch: getMachines|standalone|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|standalone - schema: - $ref: discriminator#/properties/allowedMachine-standalone-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed/properties/cpu - type: input - - label: - text: Memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|standalone|max - disableUnselect: true - fetch: getMachines|standalone|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|standalone - schema: - $ref: discriminator#/properties/allowedMachine-standalone-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed/properties/cpu - type: input - - label: - text: Memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|compute/standalone - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/controlledResources - type: multiselect - - label: - text: Container Controlled Values - options: - - text: Requests And Limits - value: RequestsAndLimits - - text: Requests Only - value: RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/containerControlledValues - type: select - - elements: - - label: - text: Scaling Factor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone/properties/inMemoryStorage - show_label: true - type: single-step-form - if: mongoTypeEqualsTo|standalone|compute - label: - text: Standalone - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/standalone - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/replicaSet/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-replicaSet-max: - type: string - allowedMachine-replicaSet-min: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/standalone/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingRules + - type: input + label: Scaling Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingThreshold + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/standalone/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/upperBound + # replicaset mode + - type: block-layout + label: ReplicaSet + if: + type: function + name: mongoTypeEqualsTo|replicaSet|storage + showLabels: true elements: - - computed: setAllowedMachine|replicaSet|min - disableUnselect: true - fetch: getMachines|replicaSet|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|replicaSet - schema: - $ref: discriminator#/properties/allowedMachine-replicaSet-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|replicaSet|max - disableUnselect: true - fetch: getMachines|replicaSet|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|replicaSet - schema: - $ref: discriminator#/properties/allowedMachine-replicaSet-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|compute/replicaSet - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/controlledResources - type: multiselect - - label: - text: Container Controlled Values - options: - - text: Requests And Limits - value: RequestsAndLimits - - text: Requests Only - value: RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/containerControlledValues - type: select - - elements: - - label: - text: Scaling Factor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet/properties/inMemoryStorage - show_label: true - type: single-step-form - if: mongoTypeEqualsTo|replicaSet|compute - label: - text: ReplicaSet - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/replicaSet - show_label: true - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/shard/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-shard-max: - type: string - allowedMachine-shard-min: - type: string - elements: - - computed: setAllowedMachine|shard|min - disableUnselect: true - fetch: getMachines|shard|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|shard - schema: - $ref: discriminator#/properties/allowedMachine-shard-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|shard|max - disableUnselect: true - fetch: getMachines|shard|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|shard - schema: - $ref: discriminator#/properties/allowedMachine-shard-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|compute/shard - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/controlledResources - type: multiselect - - label: - text: Container Controlled Values - options: - - text: Requests And Limits - value: RequestsAndLimits - - text: Requests Only - value: RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/containerControlledValues - type: select - - elements: - - label: - text: Scaling Factor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard/properties/inMemoryStorage - show_label: true - type: single-step-form - label: - text: Shard - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/shard - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/configServer/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-configServer-max: - type: string - allowedMachine-configServer-min: - type: string - elements: - - computed: setAllowedMachine|configServer|min - disableUnselect: true - fetch: getMachines|configServer|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|configServer - schema: - $ref: discriminator#/properties/allowedMachine-configServer-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|configServer|max - disableUnselect: true - fetch: getMachines|configServer|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|configServer - schema: - $ref: discriminator#/properties/allowedMachine-configServer-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|compute/configServer - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/controlledResources - type: multiselect - - label: - text: Container Controlled Values - options: - - text: Requests And Limits - value: RequestsAndLimits - - text: Requests Only - value: RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/containerControlledValues - type: select - - elements: - - label: - text: Scaling Factor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer/properties/inMemoryStorage - show_label: true - type: single-step-form - label: - text: Config Server - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/configServer - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/arbiter/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/resourceDiffPercentage - type: input - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/minAllowed/properties/memory - type: input - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/minAllowed - show_label: true - type: single-step-form - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/maxAllowed/properties/memory - type: input - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/maxAllowed - show_label: true - type: single-step-form - - fetch: setControlledResources|compute/arbiter - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/controlledResources - type: multiselect - - label: - text: Container Controlled Values - options: - - text: Requests And Limits - value: RequestsAndLimits - - text: Requests Only - value: RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/containerControlledValues - type: select - - elements: - - label: - text: Scaling Factor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter/properties/inMemoryStorage - show_label: true - type: single-step-form - hideForm: true - label: - text: Arbiter - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/arbiter - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/hidden/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/resourceDiffPercentage - type: input - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/minAllowed/properties/memory - type: input - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/minAllowed - show_label: true - type: single-step-form - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/maxAllowed/properties/memory - type: input - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/maxAllowed - show_label: true - type: single-step-form - - fetch: setControlledResources|compute/hidden - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/controlledResources - type: multiselect - - label: - text: Container Controlled Values - options: - - text: Requests And Limits - value: RequestsAndLimits - - text: Requests Only - value: RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/containerControlledValues - type: select - - elements: - - label: - text: Scaling Factor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden/properties/inMemoryStorage - show_label: true - type: single-step-form - hideForm: true - label: - text: Hidden - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/hidden - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/compute/mongos/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-mongos-max: - type: string - allowedMachine-mongos-min: - type: string - elements: - - computed: setAllowedMachine|mongos|min - disableUnselect: true - fetch: getMachines|mongos|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|mongos - schema: - $ref: discriminator#/properties/allowedMachine-mongos-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|mongos|max - disableUnselect: true - fetch: getMachines|mongos|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|mongos - schema: - $ref: discriminator#/properties/allowedMachine-mongos-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - type: single-step-form - type: single-step-form - - fetch: setControlledResources|compute/mongos - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/controlledResources - type: multiselect - - label: - text: Container Controlled Values - options: - - text: Requests And Limits - value: RequestsAndLimits - - text: Requests Only - value: RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/containerControlledValues - type: select - - elements: - - label: - text: Scaling Factor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos/properties/inMemoryStorage - show_label: true - type: single-step-form - label: - text: Mongos - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/mongos - show_label: true - type: single-step-form - if: mongoTypeEqualsTo|sharded|compute - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: Scale Up DiffPercentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: Scale Down DiffPercentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - elements: - - label: - text: Objects Count Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria/properties/objectsCountDiffPercentage - type: input - - label: - text: Oplog Max Lag Seconds - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria/properties/oplogMaxLagSeconds - type: input - label: - text: Readiness Criteria - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria - show_label: true - type: single-step-form - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.10.label -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/standalone/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/standalone/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: Scaling Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingThreshold - type: input - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/standalone/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone/properties/upperBound - type: input - if: mongoTypeEqualsTo|standalone|storage - label: - text: Standalone - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/standalone - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/replicaSet/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/expansionMode - type: select - - label: - text: usageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: - elements: - - label: - text: aApplies Upto - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/replicaSet/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: Scaling Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/scalingThreshold - type: input - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/replicaSet/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/upperBound - type: input - if: mongoTypeEqualsTo|replicaSet|storage - label: - text: ReplicaSet - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet - show_label: true - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/shard/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/replicaSet/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/expansionMode + - type: input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/usageThreshold + - type: array-object-form + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/scalingRules + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/replicaSet/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/scalingRules elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/shard/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/shard/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/upperBound - type: input - - label: - text: Scaling Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/scalingThreshold - type: input - label: - text: Shard - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/configServer/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: + - type: input + label: AppliesUpto (In Storage units) + schema: appliesUpto + - type: input + label: Threshold (In %, Or In Storage Units) + schema: threshold + - type: input + label: Scaling Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/scalingThreshold + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/replicaSet/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/replicaSet/properties/upperBound + # sharded mode + - type: block-layout + showLabels: false + if: + type: function + name: mongoTypeEqualsTo|sharded|storage + elements: + - type: block-layout + label: Shard + showLabels: true elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/configServer/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/configServer/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/upperBound - type: input - - label: - text: Scaling Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/scalingThreshold - type: input - label: - text: ConfigServer - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/hidden/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/shard/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/expansionMode + - type: input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/usageThreshold + - type: array-object-form + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/scalingRules + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/shard/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/scalingRules + elements: + - type: input + label: AppliesUpto (In Storage units) + schema: appliesUpto + - type: input + label: Threshold (In %, Or In Storage Units) + schema: threshold + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/shard/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/upperBound + - type: input + label: Scaling Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/shard/properties/scalingThreshold + - type: block-layout + label: Config Server + showLabels: true elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/hidden/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/hidden/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/upperBound - type: input - - label: - text: Scaling Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/scalingThreshold - type: input - label: - text: Hidden - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden - show_label: true - type: single-step-form - if: mongoTypeEqualsTo|sharded|storage - type: single-step-form - type: single-step-form - - elements: - - elements: - - label: - text: Objects Count Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria/properties/objectsCountDiffPercentage - type: input - - label: - text: Oplog Max Lag Seconds - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria/properties/oplogMaxLagSeconds - type: input - label: - text: Readiness Criteria - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria - show_label: true - type: single-step-form - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.11.label -- form: - discriminator: - binding: - default: false - type: boolean + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/configServer/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/expansionMode + - type: input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/usageThreshold + - type: array-object-form + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/scalingRules + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/configServer/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/scalingRules + elements: + - type: input + label: AppliesUpto (In Storage units) + schema: appliesUpto + - type: input + label: Threshold (In %, Or In Storage Units) + schema: threshold + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/configServer/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/upperBound + - type: input + label: Scaling Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/configServer/properties/scalingThreshold + - type: block-layout + label: Hidden + showLabels: true + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMongoDBAutoscaler/spec/storage/hidden/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/expansionMode + - type: input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/usageThreshold + - type: array-object-form + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/scalingRules + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/hidden/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/scalingRules + elements: + - type: input + label: AppliesUpto (In Storage units) + schema: appliesUpto + - type: input + label: Threshold (In %, Or In Storage Units) + schema: threshold + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComMongoDBAutoscaler/spec/storage/hidden/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/upperBound + - type: input + label: Scaling Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/storage/properties/hidden/properties/scalingThreshold + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: block-layout + label: Readiness Criteria + showLabels: true + elements: + - type: threshold-input + label: Objects Count Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria/properties/objectsCountDiffPercentage + - type: input + label: Oplog Max Lag Seconds + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/readinessCriteria/properties/oplogMaxLagSeconds + - type: select + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + options: + - text: 5 minutes + value: 5m0s + - text: 10 minutes + value: 10m0s + - text: 30 minutes + value: 30m0s + - text: 1 hour + value: 1h0m + - text: 2 hours + value: 2h0m + - text: 5 hours + value: 5h0m + - text: 10 hours + value: 10h0m + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMongoDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: binding + label: Gateway Binding elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -type: multi-step-form + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-mongodb-editor/ui/functions.js b/charts/kubedbcom-mongodb-editor/ui/functions.js index 6b7d18b846..ddd4f15576 100644 --- a/charts/kubedbcom-mongodb-editor/ui/functions.js +++ b/charts/kubedbcom-mongodb-editor/ui/functions.js @@ -1,2198 +1,2361 @@ -// ************************* common functions ******************************************** -// eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', true) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Compute Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + // ************************* common functions ******************************************** + // eslint-disable-next-line no-empty-pattern + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function disableLableChecker({ itemCtx }) { + const { key } = itemCtx + if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true + else return false } -} -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + const resources = (resp && resp.data && resp.data.items) || [] + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } - const resources = (resp && resp.data && resp.data.items) || [] + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function isInputTypeValueFrom() { + return !isConfigMapTypeValueFrom() && !isSecretTypeValueFrom() + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + function isEqualToDiscriminatorPath( + { discriminator, getValue, watchDependency }, + value, + discriminatorPath, + ) { + watchDependency('discriminator#' + discriminatorPath) + const discriminatorValue = getValue(discriminator, discriminatorPath) + return discriminatorValue === value } -} -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} + function setValueFromModel({ getValue, model }, path) { + return getValue(model, path) + } -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -function isNotShardModeSelected({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComMongoDB/spec') - const hasShardTopology = getValue(model, '/resources/kubedbComMongoDB/spec/shardTopology') - return !hasShardTopology -} + // function isEqualToValueFromType(index, value) { + // //watchDependency('discriminator#/valueFromType') + // // const valueFrom = getValue(discriminator, '/valueFromType') + // const valueFrom = getValue( + // model, + // '/resources/kubedbComMongoDB/spec/monitor/prometheus/exporter/env', + // ) + // return valueFrom[index].valueFromType === value + // } -function isShardModeSelected({ model, getValue, watchDependency, commit }) { - const resp = !isNotShardModeSelected({ model, getValue, watchDependency }) - if (resp) { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') + function isNotShardModeSelected({ model, getValue, watchDependency }) { + watchDependency('model#/resources/kubedbComMongoDB/spec') + const hasShardTopology = getValue(model, '/resources/kubedbComMongoDB/spec/shardTopology') + return !hasShardTopology } - return resp -} -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function isShardModeSelected({ model, getValue, watchDependency, commit }) { + const resp = !isNotShardModeSelected({ model, getValue, watchDependency }) + if (resp) { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/configSecret') + commit('wizard/model$delete', '/resources/secret_config') + } + return resp + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } - return ans -} + async function getResourceList(axios, storeGet, { group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} - -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { + let resources = await getResourceList(axios, storeGet, { + group, + version, + resource, + }) -function returnTrue() { - return true -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function returnStringYes() { - return 'yes' -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -// ************************* Basic Info ********************************************** -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function returnTrue() { + return true + } - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + function returnStringYes() { + return 'yes' } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, + // ************************* Basic Info ********************************************** + async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, }, - ) + } - const resources = (resp && resp.data && resp.data.items) || [] + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const resources = (resp && resp.data && resp.data.items) || [] - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] + // keep only non deprecated versions + const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + + filteredMongoDbVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMongoDbVersions + } catch (e) { + console.log(e) + return [] + } } -} -// ************************* Auth Secret Field ****************************************** -function showAuthPasswordField({ model, getValue, watchDependency }) { - watchDependency('model#/resources') - const modelPathValue = getValue(model, '/resources') - return !!( - modelPathValue && - modelPathValue.secret && - modelPathValue.secret.metadata && - modelPathValue.secret.metadata.name && - !showAuthSecretField({ model, getValue, watchDependency }) - ) -} + // ************************* Auth Secret Field ****************************************** + function showAuthPasswordField({ model, getValue, watchDependency }) { + watchDependency('model#/resources') + const modelPathValue = getValue(model, '/resources') + return !!( + modelPathValue && + modelPathValue.secret && + modelPathValue.secret.metadata && + modelPathValue.secret.metadata.name && + !showAuthSecretField({ model, getValue, watchDependency }) + ) + } -function showAuthSecretField({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComMongoDB/spec') - const modelPathValue = getValue(model, '/resources/kubedbComMongoDB/spec') - return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) -} + function showAuthSecretField({ model, getValue, watchDependency }) { + watchDependency('model#/resources/kubedbComMongoDB/spec') + const modelPathValue = getValue(model, '/resources/kubedbComMongoDB/spec') + return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) + } -function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { - const resp = - !showAuthSecretField({ model, getValue, watchDependency }) && - !showAuthPasswordField({ model, getValue, watchDependency }) - const secret = getValue(model, '/resources/secret_auth') - if (resp && !secret) { - commit('wizard/model$update', { - path: '/resources/secret_auth', - value: { - data: { - password: '', + function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { + const resp = + !showAuthSecretField({ model, getValue, watchDependency }) && + !showAuthPasswordField({ model, getValue, watchDependency }) + const secret = getValue(model, '/resources/secret_auth') + if (resp && !secret) { + commit('wizard/model$update', { + path: '/resources/secret_auth', + value: { + data: { + password: '', + }, }, - }, - force: true, - }) + force: true, + }) + } + return resp } - return resp -} -// ********************* Database Mode *********************** -function isNotStandaloneMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Standalone' -} + // ********************* Database Mode *********************** + function isNotStandaloneMode({ discriminator, getValue, watchDependency }) { + watchDependency('discriminator#/activeDatabaseMode') + const mode = getValue(discriminator, '/activeDatabaseMode') + return mode !== 'Standalone' + } -function showCommonStorageClassAndSizeField({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(mode) -} -function setDatabaseMode({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/resources/kubedbComMongoDB/spec') + function showCommonStorageClassAndSizeField({ discriminator, getValue, watchDependency }) { + watchDependency('discriminator#/activeDatabaseMode') + const mode = getValue(discriminator, '/activeDatabaseMode') + const validType = ['Standalone', 'Replicaset'] + return validType.includes(mode) + } + function setDatabaseMode({ model, getValue, watchDependency }) { + const modelPathValue = getValue(model, '/resources/kubedbComMongoDB/spec') - watchDependency('model#/resources/kubedbComMongoDB/spec') - if (modelPathValue.shardTopology) { - return 'Sharded' - } else if (modelPathValue.replicaSet) { - return 'Replicaset' - } else { - return 'Standalone' + watchDependency('model#/resources/kubedbComMongoDB/spec') + if (modelPathValue.shardTopology) { + return 'Sharded' + } else if (modelPathValue.replicaSet) { + return 'Replicaset' + } else { + return 'Standalone' + } } -} -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, model, getValue, watchDependency, discriminator }, - mode, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const databaseModeShard = getValue(discriminator, '/activeDatabaseMode') === 'Sharded' - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, + let storageClassList = [] + async function getStorageClassNames( + { axios, storeGet, commit, model, getValue, watchDependency, discriminator }, + mode, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const databaseModeShard = getValue(discriminator, '/activeDatabaseMode') === 'Sharded' + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, + { + params: { + filter: { items: { metadata: { name: null, annotations: null } } }, + }, }, - }, - ) + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - storageClassList = resources - const path = - mode === 'shard' - ? '/resources/kubedbComMongoDB/spec/shardTopology/shard/storage/storageClassName' - : '/resources/kubedbComMongoDB/spec/storage/storageClassName' - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ getValue, commit, model, discriminator }) - return resources -} + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + storageClassList = resources + const path = + mode === 'shard' + ? '/resources/kubedbComMongoDB/spec/shardTopology/shard/storage/storageClassName' + : '/resources/kubedbComMongoDB/spec/storage/storageClassName' + const initialStorageClass = getValue(model, path) + if (!initialStorageClass) setStorageClass({ getValue, commit, model, discriminator }) + return resources + } -function setStorageClass({ getValue, commit, model, discriminator }) { - const deletionPolicy = getValue(model, 'resources/kubedbComMongoDB/spec/deletionPolicy') || '' - const suffix = '-retain' - let storageClass = '' + function setStorageClass({ getValue, commit, model, discriminator }) { + const deletionPolicy = getValue(model, 'resources/kubedbComMongoDB/spec/deletionPolicy') || '' + const suffix = '-retain' + let storageClass = '' - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + const simpleClassList = storageClassList.filter((item) => { + return !item.metadata?.name?.endsWith(suffix) + }) - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + const retainClassList = storageClassList.filter((item) => { + return item.metadata?.name?.endsWith(suffix) + }) - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + const defaultSimpleList = simpleClassList.filter((item) => { + return ( + item.metadata && + item.metadata.annotations && + item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] + ) + }) - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value + const defaultRetainList = retainClassList.filter((item) => { + return ( + item.metadata && + item.metadata.annotations && + item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] + ) + }) + + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + if (simpleClassList.length > 1) { + const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] + storageClass = found.value + } else if (simpleClassList.length === 1) { + storageClass = simpleClassList[0]?.value + } else { + const found = defaultRetainList.length + ? defaultRetainList[0].value + : storageClassList.length + ? storageClassList[0].value + : '' + storageClass = found + } } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value + if (retainClassList.length > 1) { + const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] + storageClass = found.value + } else if (retainClassList.length === 1) { + storageClass = retainClassList[0]?.value + } else { + const found = defaultSimpleList.length + ? defaultSimpleList[0].value + : storageClassList.length + ? storageClassList[0].value + : '' + storageClass = found + } + } + + const mode = getValue(discriminator, '/activeDatabaseMode') + + if (mode === 'Sharded') { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/shardTopology/shard/storage/storageClassName', + value: storageClass, + force: true, + }) + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/shardTopology/configServer/storage/storageClassName', + value: storageClass, + force: true, + }) + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/storage') } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/storage/storageClassName', + value: storageClass, + force: true, + }) } } - const mode = getValue(discriminator, '/activeDatabaseMode') - - if (mode === 'Sharded') { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology/shard/storage/storageClassName', - value: storageClass, - force: true, - }) + function updateConfigServerStorageClass({ getValue, model, commit }) { + const storageClass = + getValue( + model, + '/resources/kubedbComMongoDB/spec/shardTopology/shard/storage/storageClassName', + ) || '' commit('wizard/model$update', { path: '/resources/kubedbComMongoDB/spec/shardTopology/configServer/storage/storageClassName', value: storageClass, force: true, }) - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/storage') - } else { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/storage/storageClassName', - value: storageClass, - force: true, - }) } -} - -function updateConfigServerStorageClass({ getValue, model, commit }) { - const storageClass = - getValue( - model, - '/resources/kubedbComMongoDB/spec/shardTopology/shard/storage/storageClassName', - ) || '' - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, - force: true, - }) -} - -function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - const modelSpec = getValue(model, '/resources/kubedbComMongoDB/spec') - if (mode === 'Sharded') { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/podTemplate') - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - - if (!modelSpec.shardTopology) { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology', - value: { - configServer: { - replicas: 3, - storage: { - resources: { - requests: { - storage: '', + function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { + const mode = getValue(discriminator, '/activeDatabaseMode') + const modelSpec = getValue(model, '/resources/kubedbComMongoDB/spec') + if (mode === 'Sharded') { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/replicaSet') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/replicas') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/storage') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/podTemplate') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/configSecret') + + commit('wizard/model$delete', '/resources/secret_config') + + if (!modelSpec.shardTopology) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/shardTopology', + value: { + configServer: { + replicas: 3, + storage: { + resources: { + requests: { + storage: '', + }, }, }, }, - }, - mongos: { - replicas: 2, - }, - shard: { - replicas: 3, - shards: 3, - storage: { - resources: { - requests: { - storage: '', + mongos: { + replicas: 2, + }, + shard: { + replicas: 3, + shards: 3, + storage: { + resources: { + requests: { + storage: '', + }, }, }, }, }, - }, - force: true, - }) - } - } else if (mode === 'Replicaset') { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/shardTopology') + force: true, + }) + } + } else if (mode === 'Replicaset') { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/shardTopology') + + commit('wizard/model$delete', '/resources/secret_shard_config') + commit('wizard/model$delete', '/resources/secret_configserver_config') + commit('wizard/model$delete', '/resources/secret_mongos_config') + + if (!modelSpec.replicaSet) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/replicaSet', + value: { name: '' }, + force: true, + }) + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/replicas', + value: 3, + force: true, + }) + } + } else if (mode === 'Standalone') { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/shardTopology') - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/replicaSet') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/replicas') - if (!modelSpec.replicaSet) { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/replicaSet', - value: { name: '' }, - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/replicas', - value: 3, - force: true, - }) + commit('wizard/model$delete', '/resources/secret_shard_config') + commit('wizard/model$delete', '/resources/secret_configserver_config') + commit('wizard/model$delete', '/resources/secret_mongos_config') } - } else if (mode === 'Standalone') { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/shardTopology') - - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/replicas') - - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') } -} -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} + function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { + watchDependency('discriminator#/activeDatabaseMode') + const mode = getValue(discriminator, '/activeDatabaseMode') + return mode === value + } -// ************************** TLS ******************************88 + // ************************** TLS ******************************88 -function setApiGroup() { - return 'cert-manager.io' -} + function setApiGroup() { + return 'cert-manager.io' + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComMongoDB/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComMongoDB/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComMongoDB/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComMongoDB/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') + async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + watchDependency('model#/resources/kubedbComMongoDB/spec/tls/issuerRef/apiGroup') + watchDependency('model#/resources/kubedbComMongoDB/spec/tls/issuerRef/kind') + watchDependency('model#/metadata/release/namespace') + const apiGroup = getValue(model, '/resources/kubedbComMongoDB/spec/tls/issuerRef/apiGroup') + const kind = getValue(model, '/resources/kubedbComMongoDB/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/release/namespace') - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } + let url + if (kind === 'Issuer') { + url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` + } else if (kind === 'ClusterIssuer') { + url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + } - if (!url) return [] + if (!url) return [] - try { - const resp = await axios.get(url) + try { + const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { + const resp = await getIssuerRefsName({ + axios, + storeGet, + getValue, + model, + watchDependency, + }) - return !!(resp && resp.length) -} + return !!(resp && resp.length) + } -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { + const resp = await hasIssuerRefName({ + axios, + storeGet, + getValue, + model, + watchDependency, + }) - return !resp -} + return !resp + } -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComMongoDB/spec/clusterAuthMode') - return val || 'x509' -} + function setClusterAuthMode({ model, getValue }) { + const val = getValue(model, '/resources/kubedbComMongoDB/spec/clusterAuthMode') + return val || 'x509' + } -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComMongoDB/spec/sslMode') - return val || 'requireSSL' -} + function setSSLMode({ model, getValue }) { + const val = getValue(model, '/resources/kubedbComMongoDB/spec/sslMode') + return val || 'requireSSL' + } -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} + function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { + watchDependency('discriminator#/configureTLS') + const configureStatus = getValue(discriminator, '/configureTLS') + return configureStatus + } -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/clusterAuthMode') - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/sslMode') + function onTlsConfigureChange({ discriminator, getValue, commit }) { + const configureStatus = getValue(discriminator, '/configureTLS') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/tls', + value: { issuerRef: {}, certificates: [] }, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/tls') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/clusterAuthMode') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/sslMode') + } } -} -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } -/****** Monitoring *********/ + /****** Monitoring *********/ -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } + + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/monitor') + } -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/monitor', - value: {}, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/monitor') } - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/monitor/prometheus/exporter') + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/monitor/prometheus/exporter') + } } -} -// ********************************* Initialization & Backup ************************************* + // ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', + const stashAppscodeComRestoreSession_init = { + spec: { + repository: { name: '', }, + rules: [ + { + snapshots: ['latest'], + }, + ], + target: { + ref: { + apiVersion: 'appcatalog.appscode.com/v1alpha1', + kind: 'AppBinding', + name: '', + }, + }, }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', + } + const initScript = { + scriptPath: '', + secret: { + secretName: '', + }, + } + const stashAppscodeComRepository_init_repo = { + spec: { + backend: { + gcs: { + bucket: '', + prefix: '', + }, + storageSecretName: '', }, - storageSecretName: '', }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', + } + const stashAppscodeComRepository_repo = { + spec: { + backend: { + gcs: { + bucket: '', + prefix: '', + }, + storageSecretName: '', }, - storageSecretName: '', }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', + } + const restoreSessionInitRunTimeSettings = { + container: { + resources: { + requests: { + cpu: '', + memory: '', + }, + limits: { + cpu: '', + memory: '', + }, }, - limits: { - cpu: '', - memory: '', + nice: { + adjustment: null, }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', + ionice: { + class: null, + classData: null, + }, + securityContext: { + privileged: false, + runAsNonRoot: false, + runAsUser: null, + runAsGroup: null, + seLinuxOptions: { + level: '', + role: '', + type: '', + user: '', + }, }, + env: [], + envFrom: [], }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', + pod: { + serviceAccountName: '', + imagePullSecrets: [], + securityContext: { + fsGroup: null, + runAsNonRoot: false, + runAsUser: null, + runAsGroup: null, + seLinuxOptions: { + level: '', + role: '', + type: '', + user: '', + }, }, }, - }, -} + } -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', + const stashAppscodeComBackupConfiguration = { + spec: { + repository: { name: '', }, + retentionPolicy: { + keepLast: 5, + name: 'keep-last-5', + prune: true, + }, + schedule: '*/5 * * * *', + target: { + ref: { + apiVersion: 'appcatalog.appscode.com/v1alpha1', + kind: 'AppBinding', + name: '', + }, + }, }, - }, -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComMongoDB/spec/init/initialized') - watchDependency('model#/resources/kubedbComMongoDB/spec/init/initialized') - return !!initialized -} + } -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} + function disableInitializationSection({ model, getValue, watchDependency }) { + const initialized = getValue(model, '/resources/kubedbComMongoDB/spec/init/initialized') + watchDependency('model#/resources/kubedbComMongoDB/spec/init/initialized') + return !!initialized + } -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComMongoDB/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComMongoDB/spec/init/script') + function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false + } - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + function initPrePopulateDatabase({ getValue, model }) { + const waitForInitialRestore = getValue( + model, + '/resources/kubedbComMongoDB/spec/init/waitForInitialRestore', + ) + const stashAppscodeComRestoreSession_init = getValue( + model, + '/resources/stashAppscodeComRestoreSession_init', + ) + const script = getValue(model, '/resources/kubedbComMongoDB/spec/init/script') -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) + return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' + } + function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { + const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') + if (prePopulateDatabase === 'no') { + // delete related properties commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, + path: '/resources/kubedbComMongoDB/spec/init/waitForInitialRestore', + value: false, }) + commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/init/script') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') + } else { + const dbName = getValue(model, '/metadata/release/name') + // set stashAppscodeComRestoreSession_init if it doesn't exist + if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComRestoreSession_init', + value: stashAppscodeComRestoreSession_init, + force: true, + }) + + commit('wizard/model$update', { + path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', + value: dbName, + force: true, + }) + } } } -} -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComMongoDB/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) + function initDataSource({ getValue, model }) { + const script = getValue(model, '/resources/kubedbComMongoDB/spec/init/script') + const stashAppscodeComRestoreSession_init = getValue( + model, + '/resources/stashAppscodeComRestoreSession_init', + ) - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} + if (script) return 'script' + else if (stashAppscodeComRestoreSession_init) return 'stashBackup' + else return undefined + } -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') + function onDataSourceChange({ commit, getValue, discriminator, model }) { + const dataSource = getValue(discriminator, '/dataSource') - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/init/waitForInitialRestore', + value: dataSource === 'stashBackup', + force: true, + }) - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') + if (dataSource === 'script') { + commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') + + // create a new script if there is no script property + if (!valueExists(model, getValue, '/resources/kubedbComMongoDB/spec/init/script')) + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/init/script', + value: initScript, + }) + } else if (dataSource === 'stashBackup') { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/init/script') + + // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property + if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { + const dbName = getValue(model, '/metadata/release/name') + + commit('wizard/model$update', { + path: '/resources/stashAppscodeComRestoreSession_init', + value: stashAppscodeComRestoreSession_init, + }) + + commit('wizard/model$update', { + path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', + value: dbName, + force: true, + }) + } + } + } - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComMongoDB/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/init/script') + // // for script + function initVolumeType({ getValue, model }) { + const configMap = getValue(model, '/resources/kubedbComMongoDB/spec/init/script/configMap/name') + const secret = getValue(model, '/resources/kubedbComMongoDB/spec/init/script/secret/secretName') - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') + if (configMap) return 'configMap' + else if (secret) return 'secret' + else return undefined + } - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) + function onVolumeTypeChange({ commit, getValue, discriminator, model }) { + const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') + if (sourceVolumeType === 'configMap') { + // add configMap object and delete secret object + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/init/script/secret') - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) + if (!valueExists(model, getValue, '/resources/kubedbComMongoDB/spec/init/script/configMap')) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/init/script/configMap', + value: { + name: '', + }, + }) + } + } else if (sourceVolumeType === 'secret') { + // delete configMap object and add secret object + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/init/script/configMap') + + if (!valueExists(model, getValue, '/resources/kubedbComMongoDB/spec/init/script/secret')) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/init/script/secret', + value: { + secretName: '', + }, + }) + } } } -} -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComMongoDB/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComMongoDB/spec/init/script/secret/secretName') + function showInitializationForm({ getValue, discriminator, watchDependency }) { + const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') + watchDependency('discriminator#/prePopulateDatabase') + return prePopulateDatabase === 'yes' + } - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} + function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { + const dataSource = getValue(discriminator, '/dataSource') + watchDependency('discriminator#/dataSource') + return dataSource === value + } -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/init/script/secret') + function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { + const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') + watchDependency('discriminator#/sourceVolumeType') + return sourceVolumeType === value + } - if (!valueExists(model, getValue, '/resources/kubedbComMongoDB/spec/init/script/configMap')) { + // for stash backup + function initializeNamespace({ getValue, model }) { + const namespace = getValue(model, '/metadata/release/namespace') + return namespace + } + + function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { + const repositoryChoise = getValue(discriminator, '/repositoryChoise') + watchDependency('discriminator#/repositoryChoise') + + return repositoryChoise === value + } + + function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { + const repositoryChoise = getValue(discriminator, '/repositoryChoise') + if (repositoryChoise === 'select') { + // delete stashAppscodeComRepository_init_repo from model + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') + } else if (repositoryChoise === 'create') { + // add stashAppscodeComRepository_init_repo to model commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/init/script/configMap', - value: { - name: '', - }, + path: 'resources/stashAppscodeComRepository_init_repo', + value: stashAppscodeComRepository_init_repo, }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/init/script/configMap') - if (!valueExists(model, getValue, '/resources/kubedbComMongoDB/spec/init/script/secret')) { + const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` + // set this name in stashAppscodeComRestoreSession_init commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/init/script/secret', - value: { - secretName: '', - }, + path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', + value: repositoryName, }) } } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) + function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { + const runtimeSettings = getValue( + model, + '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', + ) + if (runtimeSettings) return 'yes' + else return 'no' } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} + function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { + const runtimeSettings = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + ) + if (runtimeSettings) return 'yes' + else return 'no' + } -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', + function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { + const customizeRestoreJobRuntimeSettings = getValue( + discriminator, + '/customizeRestoreJobRuntimeSettings', ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, + if (customizeRestoreJobRuntimeSettings === 'no') { + commit( + 'wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) + } else if (customizeRestoreJobRuntimeSettings === 'yes') { + if ( + !valueExists( + model, + getValue, + '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', + ) + ) { + // set new value + commit('wizard/model$update', { + path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', + value: restoreSessionInitRunTimeSettings, + }) + } } } -} -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( + function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ + commit, + getValue, discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + model, + }) { + const customizeRestoreJobRuntimeSettings = getValue( + discriminator, + '/customizeRestoreJobRuntimeSettings', ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, + if (customizeRestoreJobRuntimeSettings === 'no') { + commit( + 'wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) + } else if (customizeRestoreJobRuntimeSettings === 'yes') { + if ( + !valueExists( + model, + getValue, + '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + ) + ) { + // set new value + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + value: {}, + force: true, + }) + } } } -} -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} + function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { + const customizeRestoreJobRuntimeSettings = getValue( + discriminator, + '/customizeRestoreJobRuntimeSettings', + ) + watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') + return customizeRestoreJobRuntimeSettings === value + } -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { + const namespace = getValue(model, '/metadata/release/namespace') + watchDependency('model#/metadata/release/namespace') - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group: 'core', + version: 'v1', + resource: 'secrets', + }) + + resources = resources.filter((item) => { + const validType = ['kubernetes.io/dockerconfigjson'] + return validType.includes(item.type) + }) - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: { name: name }, + } + }) + } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, + function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { + const backupEnabled = getValue(discriminator, '/backupEnabled') + if (backupEnabled) { + if (backup === 'alert') return true + else return false + } else { + if (backup === 'alert') return false + else return true } - }) -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true } -} -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} + function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { + watchDependency('discriminator#/blueprintOptions') + const blueprintOptions = getValue(discriminator, '/blueprintOptions') + return blueprintOptions === value + } -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} + function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { + watchDependency( + 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', + ) + const usagePolicy = getValue( + model, + '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', + ) + return usagePolicy === value + } -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` + async function getBlueprints( + { getValue, model, setDiscriminatorValue, axios, storeGet }, + backup, + ) { + const username = storeGet('/route/params/user') + const clusterName = storeGet('/route/params/cluster') + const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) + try { + const resp = await axios.get(url) + let data = resp.data.items + return data + } catch (e) { + console.log(e) + } } -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged({ storeGet }) { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') + async function fetchNamespaces({ axios, storeGet }) { + const username = storeGet('/route/params/user') + const clusterName = storeGet('/route/params/cluster') + const group = storeGet('/route/params/group') + const version = storeGet('/route/params/version') + const resource = storeGet('/route/params/resource') - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` + const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + try { + const resp = await axios.post(url, { + _recurringCall: false, + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data + async function fetchNames( + { getValue, axios, storeGet, watchDependency, discriminator }, + version, + type, + discriminatorName, + ) { + watchDependency(`discriminator#/${discriminatorName}`) + const username = storeGet('/route/params/user') + const clusterName = storeGet('/route/params/cluster') + const namespace = getValue(discriminator, `${discriminatorName}`) + const url = + type !== 'secrets' + ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` + : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` + try { + if (namespace) { + const resp = await axios.get(url) + let data = resp.data.items + if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) + data = data.map((ele) => ele.metadata.name) + return data + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// FOR Backup Configuration + // FOR Backup Configuration -// schedule backup + // schedule backup -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) + function getBackupConfigsAndAnnotations(getValue, model) { + const stashAppscodeComBackupConfiguration = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration', + ) - const coreKubestashComBackupConfiguration = getValue( - model, - '/resources/coreKubestashComBackupConfiguration', - ) - const kubeStashTarget = coreKubestashComBackupConfiguration?.spec?.target + const coreKubestashComBackupConfiguration = getValue( + model, + '/resources/coreKubestashComBackupConfiguration', + ) + const kubeStashTarget = coreKubestashComBackupConfiguration?.spec?.target + + const mongoDB = getValue(model, '/resources/kubedbComMongoDB') + const mongoDbKind = mongoDB?.apiVersion?.split('/')?.at(0) - const mongoDB = getValue(model, '/resources/kubedbComMongoDB') - const mongoDbKind = mongoDB?.apiVersion?.split('/')?.at(0) + let isKubeStash = false + if ( + mongoDB?.kind === kubeStashTarget?.kind && + mongoDB?.metadata?.name === kubeStashTarget?.name && + mongoDB?.metadata?.namespace === kubeStashTarget?.namespace && + mongoDbKind === kubeStashTarget?.apiGroup + ) { + isKubeStash = true + } - let isKubeStash = false - if ( - mongoDB?.kind === kubeStashTarget?.kind && - mongoDB?.metadata?.name === kubeStashTarget?.name && - mongoDB?.metadata?.namespace === kubeStashTarget?.namespace && - mongoDbKind === kubeStashTarget?.apiGroup - ) { - isKubeStash = true - } + const kubedbComMongoDBAnnotations = + getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') || {} - const kubedbComMongoDBAnnotations = - getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') || {} + const isBluePrint = Object.keys(kubedbComMongoDBAnnotations).some( + (k) => + k === 'stash.appscode.com/backup-blueprint' || + k === 'stash.appscode.com/schedule' || + k.startsWith('params.stash.appscode.com/'), + ) - const isBluePrint = Object.keys(kubedbComMongoDBAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) + return { + stashAppscodeComBackupConfiguration, + isBluePrint, + isKubeStash, + } + } - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - isKubeStash, + function deleteKubeDbComMongDbAnnotation(getValue, model, commit) { + const annotations = getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') || {} + const filteredKeyList = + Object.keys(annotations).filter( + (k) => + k !== 'stash.appscode.com/backup-blueprint' && + k !== 'stash.appscode.com/schedule' && + !k.startsWith('params.stash.appscode.com/'), + ) || [] + const filteredAnnotations = {} + filteredKeyList.forEach((k) => { + filteredAnnotations[k] = annotations[k] + }) + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/metadata/annotations', + value: filteredAnnotations, + }) } -} -function deleteKubeDbComMongDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/metadata/annotations', - value: filteredAnnotations, - }) -} + function addKubeDbComMongDbAnnotation(getValue, model, commit, key, value, force) { + const annotations = getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') || {} -function addKubeDbComMongDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') || {} + if (annotations[key] === undefined) { + annotations[key] = value + } else if (force) { + annotations[key] = value + } - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/metadata/annotations', + value: annotations, + force: true, + }) } - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) + initRepositoryChoiseForEdit() - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' + } -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + function initScheduleBackup({ getValue, model }) { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' + } -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') + function onScheduleBackupChange() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from KubeDBComMongoDB annotation - deleteKubeDbComMongDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) + if (scheduleBackup === 'no') { + // delete stashAppscodeComBackupConfiguration + commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + // delete annotation from KubeDBComMongoDB annotation + deleteKubeDbComMongDbAnnotation(getValue, model, commit) + } else { + const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - // create stashAppscodeComBackupConfiguration and initialize it if not exists + // create stashAppscodeComBackupConfiguration and initialize it if not exists - const dbName = getValue(model, '/metadata/release/name') + const dbName = getValue(model, '/metadata/release/name') - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) + if ( + !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && + !isBluePrint + ) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration', + value: stashAppscodeComBackupConfiguration, + }) + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + } } } -} -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} + // backup form + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false + } -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') + // backup configuration form + function initalizeTargetReferenceName({ getValue, model, watchDependency }) { + const databaseName = getValue(model, '/metadata/release/name') + watchDependency('model#/metadata/release/name') - return databaseName -} + return databaseName + } -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} + // restore session repository + function setInitialRestoreSessionRepo({ getValue, model }) { + const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') + return value ? 'create' : 'select' + } -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) + // backup config repository + function initRepositoryChoise({ getValue, model }) { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} + if (stashAppscodeComRepository_repo) return 'create' + else return 'select' + } -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) + + return repoInitialSelectionStatus + } + + function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { + const repositoryChoise = getValue(discriminator, '/repositoryChoise') + watchDependency('discriminator#/repositoryChoise') + + if (repositoryChoise === 'select') { + // delete the stashAppscodeComRepository_repo + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + } else if (repositoryChoise === 'create') { + // create new stashAppscodeComRepository_repo + if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComRepository_repo', + value: stashAppscodeComRepository_repo, + }) + const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` + // set this name in stashAppscodeComRestoreSession_init + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', + value: repositoryName, + }) + } + } + } - return repoInitialSelectionStatus -} + function onRepositoryNameChange({ getValue, model, commit }) { + const repositoryName = getValue( + model, + 'resources/stashAppscodeComRepository_repo/metadata/name', + ) + // set this name in stashAppscodeComRestoreSession_init + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', + value: repositoryName, + }) + } -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + function onInputChange( + { getValue, discriminator, watchDependency, commit, model }, + modelPath, + field, + subfield, + discriminatorName, + ) { + const value = getValue(discriminator, `/${discriminatorName}`) + const backends = getValue(model, modelPath) || [] + if (field !== 'encryptionSecret') backends[0][field][subfield] = value + else backends[0]['repositories'][0][field][subfield] = value + commit('wizard/model$update', { + path: modelPath, + value: backends, + }) + } + function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { + const backends = getValue(model, modelPath) + if (field !== 'encryptionSecret') backends[0][field][subfield] = value + else backends[0]['repositories'][0][field][subfield] = value + commit('wizard/model$update', { + path: modelPath, + value: backends, + }) + } - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, + path: modelPath, + value: session, + force: true, }) } } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} -function onInputChange( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) || [] - if (session.length) { + function setInitSchedule( + { getValue, discriminator, watchDependency, commit, model }, + modelPath, + value, + ) { + const session = getValue(model, modelPath) session[0].scheduler.schedule = value commit('wizard/model$update', { path: modelPath, value: session, - force: true, }) } -} - -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] + function getDefault({ getValue, model }, modelPath, field, subfield) { + const backends = getValue(model, modelPath) + if (field !== 'encryptionSecret') return backends[0][field][subfield] + else { + return backends[0]['repositories'][0][field][subfield] + } } -} -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' + } + + // restructure backup modal + + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let namespaceList = [] + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComMongoDB') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined -// restructure backup modal - -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -async function initBackupData({ storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComMongoDB') - initialDbMetadata = objectCopy(dbResource.metadata) - initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check storageclass archiver annotation - if (initialArchiver) { - isArchiverAvailable = true - } else { - const storageClassName = dbResource?.spec?.storage?.storageClassName - const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + // get values.yaml to populate data when backup-config is being created try { + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version + + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` + + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` + const resp = await axios.get(url) - const archAnnotation = resp.data?.metadata?.annotations - const annotationKeyToFind = `${resource}.${group}/archiver` - if (archAnnotation[annotationKeyToFind]) { - isArchiverAvailable = true - archiverObjectToCommit = { - ref: { - name: archAnnotation[annotationKeyToFind], - namespace: 'kubedb', - }, - } - } + + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} } catch (e) { console.log(e) } - } - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } + } - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( + // check config with metadata name first + let config = configs?.find( (item) => + item.metadata?.name === name && item.spec?.target?.name === name && item.spec?.target?.namespace === namespace && item.spec?.target?.kind === kind && item.spec?.target?.apiGroup === group, ) - // set backup switch here - isBackupOn = !!config + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset + // set backup switch here + isBackupOn = !!config - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions - } + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, - } + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions + } - setDiscriminatorValue('isBackupDataLoaded', true) -} + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} + setDiscriminatorValue('isBackupDataLoaded', true) + } -async function setBackupType() { - return 'BackupConfig' -} + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') + } -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] + function setBackupType() { + return 'BackupConfig' + } - if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { - arr.push({ - description: 'Enable/Disable Archiver', - text: 'Archiver', - value: 'Archiver', - }) + function getTypes() { + const arr = [ + { + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', + }, + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] + + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) + } + return arr } - return arr -} -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), + path: '/backupType', + value: type, + force: true, + }) + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), + force: true, + }) + } + commit('wizard/model$delete', '/context') + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB', + value: objectCopy(dbResource), force: true, }) } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB', - value: objectCopy(dbResource), - force: true, - }) -} -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') - return selectedType === type -} + return selectedType === type + } -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) + } -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') + if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') + else deleteLabelAnnotation(commit, 'annotations') + } -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver + } + + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComMongoDB/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) + } else { + commit('wizard/model$delete', path) + } + } + + function addLabelAnnotation(commit, storeGet, type) { + const obj = objectCopy(initialDbMetadata[type]) + + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` + } else { + obj['kubedb.com/archiver'] = 'true' + } -function onArchiverChange({ getValue, discriminator, commit, model, storeGet }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComMongoDB/spec/archiver' - if (archiverSwitch) { commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, + path: `/resources/kubedbComMongoDB/metadata/${type}`, + value: obj, + force: true, }) - } else { - commit('wizard/model$delete', path) } -} -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) + function deleteLabelAnnotation(commit, type) { + const obj = initialDbMetadata[type] - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' - } + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] - commit('wizard/model$update', { - path: `/resources/kubedbComMongoDB/metadata/${type}`, - value: obj, - force: true, - }) -} + commit('wizard/model$update', { + path: `/resources/kubedbComMongoDB/metadata/${type}`, + value: obj, + force: true, + }) + } -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') + commit('wizard/model$update', { + path: '/context', + value: context, + force: true, + }) + if (context === 'Create') { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, + force: true, + }) + } + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) + } - commit('wizard/model$update', { - path: `/resources/kubedbComMongoDB/metadata/${type}`, - value: obj, - force: true, - }) -} + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) + const list = filteredList?.map((ele) => ele.metadata.name) + return list + } -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { commit('wizard/model$update', { path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, + value: configDetails, force: true, }) } -} -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' + } -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' + } - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName + } -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} + function getNamespaceArray() { + return namespaceList + } -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} + // backup blueprint form + function getMongoAnnotations(getValue, model) { + const annotations = getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') + return { ...annotations } || {} + } -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} + function initFromAnnotationValue({ getValue, model }, key) { + const annotations = getMongoAnnotations(getValue, model) + return annotations[key] + } -function getNamespaceArray() { - return namespaceList -} + function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { + const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') + addKubeDbComMongDbAnnotation( + getValue, + model, + commit, + 'stash.appscode.com/backup-blueprint', + backupBlueprintName, + true, + ) + } -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') - return { ...annotations } || {} -} + function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { + const backupBlueprintSchedule = getValue(discriminator, '/schedule') + addKubeDbComMongDbAnnotation( + getValue, + model, + commit, + 'stash.appscode.com/schedule', + backupBlueprintSchedule, + true, + ) + } -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} + function initFromAnnotationKeyValue({ getValue, model }, prefix) { + const annotations = getMongoAnnotations(getValue, model) + const newOb = {} + Object.keys(annotations).forEach((key) => { + if (key.startsWith(prefix)) { + const newKey = key.replace(prefix, '') + newOb[newKey] = annotations[key] + } + }) + return newOb + } -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} + function onTaskParametersChange({ getValue, discriminator, model, commit }) { + const taskParameters = getValue(discriminator, '/taskParameters') -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} + const taskParamterKeys = Object.keys(taskParameters).map( + (tp) => `params.stash.appscode.com/${tp}`, + ) + const oldAnnotations = getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') || {} + const newAnnotations = {} -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} + const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( + (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), + ) + + filteredAnnotationKeys.forEach((key) => { + newAnnotations[key] = oldAnnotations[key] + }) -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') + Object.keys(taskParameters).forEach((tpk) => { + newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] + }) - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComMongoDB/metadata/annotations') || {} - const newAnnotations = {} + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/metadata/annotations', + value: newAnnotations, + }) + } + + function isValueExistInModel(path) { + const modelValue = getValue(model, path) + return !!modelValue + } + + function onNamespaceChange({ commit, model, getValue }) { + const namespace = getValue(model, '/metadata/release/namespace') + const agent = getValue(model, '/resources/kubedbComMongoDB/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + value: [namespace], + force: true, + }) + } + } - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) + function onLabelChange({ commit, model, getValue }) { + const labels = getValue(model, '/resources/kubedbComMongoDB/spec/metadata/labels') - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) + const agent = getValue(model, '/resources/kubedbComMongoDB/spec/monitor/agent') - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) + } + } - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/metadata/annotations', - value: newAnnotations, - }) -} + function onNameChange({ commit, model, getValue }) { + const dbName = getValue(model, '/metadata/release/name') -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} + const agent = getValue(model, '/resources/kubedbComMongoDB/spec/monitor/agent') -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComMongoDB/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} + const labels = getValue(model, '/resources/kubedbComMongoDB/spec/metadata/labels') -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComMongoDB/spec/metadata/labels') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) + } - const agent = getValue(model, '/resources/kubedbComMongoDB/spec/monitor/agent') + const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} + if (scheduleBackup) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') + if (creatingNewRepo) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', + value: `${dbName}-repo`, + force: true, + }) + } + } -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') + const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - const agent = getValue(model, '/resources/kubedbComMongoDB/spec/monitor/agent') + if (prePopulateDatabase) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', + value: dbName, + force: true, + }) + const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') + if (creatingNewRepo) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', + value: `${dbName}-init-repo`, + force: true, + }) + } + } - const labels = getValue(model, '/resources/kubedbComMongoDB/spec/metadata/labels') + // to reset configSecret name field + const hasSecretConfig = getValue(model, '/resources/secret_config') + if (hasSecretConfig) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/configSecret/name', + value: `${dbName}-config`, + force: true, + }) + } - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } + // to reset shard configSecret name field + const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') + if (hasSecretShardConfig) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/shardTopology/shard/configSecret/name', + value: `${dbName}-shard-config`, + force: true, + }) + } - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') + // to reset shard configSecret name field + const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') + if (hasSecretConfigServerConfig) { + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/shardTopology/configServer/configSecret/name', + value: `${dbName}-configserver-config`, + force: true, + }) + } - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { + // to reset mongos configSecret name field + const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') + if (hasSecretMongosConfig) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, + path: '/resources/kubedbComMongoDB/spec/shardTopology/mongos/configSecret/name', + value: `${dbName}-mongos-config`, force: true, }) } } - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') + function returnFalse() { + return false + } - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComMongoDB/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], force: true, }) + + onNamespaceChange({ commit, model, getValue }) + onLabelChange({ commit, model, getValue }) + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } } - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } + /************************************* Database Secret Section ********************************************/ - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) + function getCreateAuthSecret({ model, getValue }) { + const authSecret = getValue(model, '/resources/kubedbComMongoDB/spec/authSecret') + + return !authSecret } - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) + function showExistingSecretSection({ getValue, watchDependency, discriminator }) { + watchDependency('discriminator#/createAuthSecret') + + const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') + return !hasAuthSecretName } - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, - force: true, + function showPasswordSection({ getValue, watchDependency, discriminator }) { + return !showExistingSecretSection({ + getValue, + watchDependency, + discriminator, }) } -} -function returnFalse() { - return false -} + function setAuthSecretPassword({ model, getValue }) { + const encodedPassword = getValue(model, '/resources/secret_auth/data/password') + return encodedPassword ? decodePassword({}, encodedPassword) : '' + } -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComMongoDB/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) + function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { + const stringPassword = getValue(discriminator, '/password') - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + if (stringPassword) { + commit('wizard/model$update', { + path: '/resources/secret_auth/data/password', + value: encodePassword({}, stringPassword), + force: true, + }) + commit('wizard/model$update', { + path: '/resources/secret_auth/data/username', + value: encodePassword({}, 'root'), + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/secret_auth') + } } -} - -/************************************* Database Secret Section ********************************************/ -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComMongoDB/spec/authSecret') + // eslint-disable-next-line no-empty-pattern + function encodePassword({}, value) { + return btoa(value) + } - return !authSecret -} + // eslint-disable-next-line no-empty-pattern + function decodePassword({}, value) { + return atob(value) + } -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') + function onCreateAuthSecretChange({ discriminator, getValue, commit }) { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/authSecret') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/resources/secret_auth') + } + } - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} + const secrets = (resp && resp.data && resp.data.items) || [] -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } } -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComMongoDB/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + if (!secretName) return [] - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secret = (resp && resp.data && resp.data.data) || {} - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] + return secretKeys + } catch (e) { + console.log(e) + return [] + } } -} -//////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// + //////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// -//////////////////// service monitor /////////////////// + //////////////////// service monitor /////////////////// -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} + function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { + watchDependency('rootModel#/spec/type') + return rootModel && rootModel.spec && rootModel.spec.type === value + } -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { + //////////////////// custom config ///////////////// + function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { + const configurationSource = getValue(discriminator, '/configurationSource') + if (configurationSource === 'use-existing-config') { + commit('wizard/model$delete', '/resources/secret_config') + } else { + const value = getValue(model, '/resources/secret_config') + if (!value) { + commit('wizard/model$update', { + path: '/resources/secret_config', + value: {}, + force: true, + }) + } + const configSecretName = `${getValue(model, '/metadata/release/name')}-config` commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, + path: '/resources/kubedbComMongoDB/spec/configSecret/name', + value: configSecretName, force: true, }) } + } + + function onConfigurationChange({ getValue, commit, discriminator, model }) { + const value = getValue(discriminator, '/configuration') + commit('wizard/model$update', { + path: '/resources/secret_config/stringData/mongod.conf', + value: value, + force: true, + }) const configSecretName = `${getValue(model, '/metadata/release/name')}-config` commit('wizard/model$update', { path: '/resources/kubedbComMongoDB/spec/configSecret/name', @@ -2200,976 +2363,1008 @@ function onConfigurationSourceChange({ getValue, discriminator, commit, model }) force: true, }) } -} -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/mongod.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' + function setConfigurationSource({ model, getValue }) { + const modelValue = getValue(model, '/resources/secret_config') + if (modelValue) { + return 'create-new-config' + } + return 'use-existing-config' } - return 'use-existing-config' -} -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -//////////////////// custom config for sharded topology ///////////////// - -function setConfigurationSourceShard({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceShard') - if (src) return src - const value = getValue(model, '/resources/secret_shard_config') - return value ? 'create-new-config' : 'use-existing-config' -} + function setSecretConfigNamespace({ getValue, model, watchDependency }) { + watchDependency('model#/metadata/release/namespace') + const namespace = getValue(model, '/metadata/release/namespace') + return namespace + } -function setConfigurationSourceConfigServer({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceConfigServer') - if (src) return src - const value = getValue(model, '/resources/secret_configserver_config') - return value ? 'create-new-config' : 'use-existing-config' -} + //////////////////// custom config for sharded topology ///////////////// -function setConfigurationSourceMongos({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceMongos') - if (src) return src - const value = getValue(model, '/resources/secret_mongos_config') - return value ? 'create-new-config' : 'use-existing-config' -} + function setConfigurationSourceShard({ model, getValue, discriminator }) { + const src = getValue(discriminator, '/configurationSourceShard') + if (src) return src + const value = getValue(model, '/resources/secret_shard_config') + return value ? 'create-new-config' : 'use-existing-config' + } -function isSchemaOf(schema) { - if (schema === 'discriminator#/configurationSourceShard') { - return 'shard' - } else if (schema === 'discriminator#/configurationSourceConfigServer') { - return 'configserver' - } else { - return 'mongos' + function setConfigurationSourceConfigServer({ model, getValue, discriminator }) { + const src = getValue(discriminator, '/configurationSourceConfigServer') + if (src) return src + const value = getValue(model, '/resources/secret_configserver_config') + return value ? 'create-new-config' : 'use-existing-config' } -} -function disableConfigSourceOption({ - itemCtx, - discriminator, - getValue, - watchDependency, - elementUi, -}) { - watchDependency('discriminator#/configurationSourceShard') - watchDependency('discriminator#/configurationSourceConfigServer') - watchDependency('discriminator#/configurationSourceMongos') - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - if ( - itemCtx.value !== 'use-existing-config' && - itemCtx.value !== 'create-new-config' && - (configSrcShard === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcConfigServer === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcMongos === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret`) - ) { - return true + function setConfigurationSourceMongos({ model, getValue, discriminator }) { + const src = getValue(discriminator, '/configurationSourceMongos') + if (src) return src + const value = getValue(model, '/resources/secret_mongos_config') + return value ? 'create-new-config' : 'use-existing-config' } - if ( - itemCtx.value === 'same-as-shard-config-secret' && - configSrcShard !== 'use-existing-config' && - configSrcShard !== 'create-new-config' - ) { - return true + + function isSchemaOf(schema) { + if (schema === 'discriminator#/configurationSourceShard') { + return 'shard' + } else if (schema === 'discriminator#/configurationSourceConfigServer') { + return 'configserver' + } else { + return 'mongos' + } } - if ( - itemCtx.value === 'same-as-configserver-config-secret' && - configSrcConfigServer !== 'use-existing-config' && - configSrcConfigServer !== 'create-new-config' - ) { - return true + + function disableConfigSourceOption({ + itemCtx, + discriminator, + getValue, + watchDependency, + elementUi, + }) { + watchDependency('discriminator#/configurationSourceShard') + watchDependency('discriminator#/configurationSourceConfigServer') + watchDependency('discriminator#/configurationSourceMongos') + const configSrcShard = getValue(discriminator, '/configurationSourceShard') + const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') + const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') + if ( + itemCtx.value !== 'use-existing-config' && + itemCtx.value !== 'create-new-config' && + (configSrcShard === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || + configSrcConfigServer === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || + configSrcMongos === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret`) + ) { + return true + } + if ( + itemCtx.value === 'same-as-shard-config-secret' && + configSrcShard !== 'use-existing-config' && + configSrcShard !== 'create-new-config' + ) { + return true + } + if ( + itemCtx.value === 'same-as-configserver-config-secret' && + configSrcConfigServer !== 'use-existing-config' && + configSrcConfigServer !== 'create-new-config' + ) { + return true + } + if ( + itemCtx.value === 'same-as-mongos-config-secret' && + configSrcMongos !== 'use-existing-config' && + configSrcMongos !== 'create-new-config' + ) { + return true + } + return false + } + + function onConfigurationSourceMongosChange({ getValue, discriminator, commit, model }) { + const configurationSource = getValue(discriminator, '/configurationSourceMongos') + const configSecretName = `${getValue(model, '/metadata/release/name')}-mongos-config` + if (configurationSource === 'use-existing-config') { + commit('wizard/model$delete', '/resources/secret_mongos_config') + onConfigSecretModelChange( + { commit, model, getValue, discriminator }, + 'mongos', + configurationSource, + '/configurationMongos', + ) + } else if (configurationSource === 'create-new-config') { + const value = getValue(model, '/resources/secret_mongos_config') + if (!value) { + commit('wizard/model$update', { + path: '/resources/secret_mongos_config', + value: {}, + force: true, + }) + } + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/shardTopology/mongos/configSecret/name', + value: configSecretName, + force: true, + }) + onConfigSecretModelChange( + { commit, model, getValue, discriminator }, + 'mongos', + configurationSource, + '/configurationMongos', + ) + } else if (configurationSource === 'same-as-shard-config-secret') { + transferConfigSecret({ commit, model, getValue }, 'shard', 'mongos') + } else if (configurationSource === 'same-as-configserver-config-secret') { + transferConfigSecret({ commit, model, getValue }, 'configserver', 'mongos') + } } - if ( - itemCtx.value === 'same-as-mongos-config-secret' && - configSrcMongos !== 'use-existing-config' && - configSrcMongos !== 'create-new-config' - ) { - return true + + function onConfigurationSourceShardChange({ getValue, discriminator, commit, model }) { + const configurationSource = getValue(discriminator, '/configurationSourceShard') + const configSecretName = `${getValue(model, '/metadata/release/name')}-shard-config` + if (configurationSource === 'use-existing-config') { + commit('wizard/model$delete', '/resources/secret_shard_config') + onConfigSecretModelChange( + { commit, model, getValue, discriminator }, + 'shard', + configurationSource, + '/configurationShard', + ) + } else if (configurationSource === 'create-new-config') { + const value = getValue(model, '/resources/secret_shard_config') + if (!value) { + commit('wizard/model$update', { + path: '/resources/secret_shard_config', + value: {}, + force: true, + }) + } + commit('wizard/model$update', { + path: '/resources/kubedbComMongoDB/spec/shardTopology/shard/configSecret/name', + value: configSecretName, + force: true, + }) + onConfigSecretModelChange( + { commit, model, getValue, discriminator }, + 'shard', + configurationSource, + '/configurationShard', + ) + } else if (configurationSource === 'same-as-configserver-config-secret') { + transferConfigSecret({ commit, model, getValue }, 'configserver', 'shard') + } else if (configurationSource === 'same-as-mongos-config-secret') { + transferConfigSecret({ commit, model, getValue }, 'mongos', 'shard') + } } - return false -} -function onConfigurationSourceMongosChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceMongos') - const configSecretName = `${getValue(model, '/metadata/release/name')}-mongos-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_mongos_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_mongos_config') - if (!value) { + function onConfigurationSourceConfigServerChange({ getValue, discriminator, commit, model }) { + const configurationSource = getValue(discriminator, '/configurationSourceConfigServer') + const configSecretName = `${getValue(model, '/metadata/release/name')}-configserver-config` + if (configurationSource === 'use-existing-config') { + commit('wizard/model$delete', '/resources/secret_configserver_config') + onConfigSecretModelChange( + { commit, model, getValue, discriminator }, + 'configserver', + configurationSource, + '/configurationConfigServer', + ) + } else if (configurationSource === 'create-new-config') { + const value = getValue(model, '/resources/secret_configserver_config') + if (!value) { + commit('wizard/model$update', { + path: '/resources/secret_configserver_config', + value: {}, + force: true, + }) + } commit('wizard/model$update', { - path: '/resources/secret_mongos_config', - value: {}, + path: '/resources/kubedbComMongoDB/spec/shardTopology/configServer/configSecret/name', + value: configSecretName, force: true, }) + onConfigSecretModelChange( + { commit, model, getValue, discriminator }, + 'configserver', + configurationSource, + '/configurationConfigServer', + ) + } else if (configurationSource === 'same-as-shard-config-secret') { + const configurationSourceReference = getValue(discriminator, '/configurationSourceShard') + transferConfigSecret( + { commit, model, getValue }, + 'shard', + 'configserver', + configurationSourceReference, + ) + } else if (configurationSource === 'same-as-mongos-config-secret') { + const configurationSourceReference = getValue(discriminator, '/configurationSourceMongos') + transferConfigSecret( + { commit, model, getValue }, + 'mongos', + 'configserver', + configurationSourceReference, + ) } - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology/mongos/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'shard', 'mongos') - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'mongos') } -} -function onConfigurationSourceShardChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceShard') - const configSecretName = `${getValue(model, '/metadata/release/name')}-shard-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_shard_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_shard_config') - if (!value) { + function transferConfigSecret({ commit, model, getValue }, src, des) { + const isShardedMode = getValue(model, '/resources/kubedbComMongoDB/spec/shardTopology') + if (isShardedMode) { commit('wizard/model$update', { - path: '/resources/secret_shard_config', - value: {}, + path: `/resources/kubedbComMongoDB/spec/shardTopology/${ + des === 'configserver' ? 'configServer' : des + }/configSecret/name`, + value: getValue( + model, + `/resources/kubedbComMongoDB/spec/shardTopology/${ + src === 'configserver' ? 'configServer' : src + }/configSecret/name`, + ), force: true, }) + + commit('wizard/model$delete', `/resources/secret_${des}_config`) } - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology/shard/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'shard') - } else if (configurationSource === 'same-as-mongos-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'mongos', 'shard') } -} -function onConfigurationSourceConfigServerChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceConfigServer') - const configSecretName = `${getValue(model, '/metadata/release/name')}-configserver-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_configserver_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_configserver_config') - if (!value) { + function onConfigSecretModelChange( + { commit, model, getValue, discriminator }, + configType, + configSrc, + discriminatorPath, + ) { + if (configSrc === 'create-new-config') { + const value = getValue(discriminator, discriminatorPath) commit('wizard/model$update', { - path: '/resources/secret_configserver_config', - value: {}, + path: `/resources/secret_${configType}_config/stringData/mongod.conf`, + value: value, force: true, }) } - commit('wizard/model$update', { - path: '/resources/kubedbComMongoDB/spec/shardTopology/configServer/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceShard') - transferConfigSecret( - { commit, model, getValue }, - 'shard', - 'configserver', - configurationSourceReference, - ) - } else if (configurationSource === 'same-as-mongos-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceMongos') - transferConfigSecret( - { commit, model, getValue }, - 'mongos', - 'configserver', - configurationSourceReference, - ) + const configSrcShard = getValue(discriminator, '/configurationSourceShard') + const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') + const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') + + if (configSrcShard === `same-as-${configType}-config-secret`) { + transferConfigSecret({ commit, model, getValue }, configType, 'shard') + } + if (configSrcConfigServer === `same-as-${configType}-config-secret`) { + transferConfigSecret({ commit, model, getValue }, configType, 'configserver') + } + if (configSrcMongos === `same-as-${configType}-config-secret`) { + transferConfigSecret({ commit, model, getValue }, configType, 'mongos') + } } -} -function transferConfigSecret({ commit, model, getValue }, src, des) { - const isShardedMode = getValue(model, '/resources/kubedbComMongoDB/spec/shardTopology') - if (isShardedMode) { - commit('wizard/model$update', { - path: `/resources/kubedbComMongoDB/spec/shardTopology/${ - des === 'configserver' ? 'configServer' : des - }/configSecret/name`, - value: getValue( - model, - `/resources/kubedbComMongoDB/spec/shardTopology/${ - src === 'configserver' ? 'configServer' : src - }/configSecret/name`, - ), - force: true, - }) + function setConfiguration({ model, getValue }) { + return getValue(model, '/resources/secret_config/stringData/mongod.conf') + } - commit('wizard/model$delete', `/resources/secret_${des}_config`) + function setConfigurationShard({ model, getValue }) { + const value = getValue(model, '/resources/secret_shard_config/stringData/mongod.conf') + return value } -} -function onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - configType, - configSrc, - discriminatorPath, -) { - if (configSrc === 'create-new-config') { - const value = getValue(discriminator, discriminatorPath) - commit('wizard/model$update', { - path: `/resources/secret_${configType}_config/stringData/mongod.conf`, - value: value, - force: true, - }) + function setConfigurationConfigServer({ model, getValue }) { + const value = getValue(model, '/resources/secret_configserver_config/stringData/mongod.conf') + return value } - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - if (configSrcShard === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'shard') + function setConfigurationMongos({ model, getValue }) { + const value = getValue(model, '/resources/secret_mongos_config/stringData/mongod.conf') + return value } - if (configSrcConfigServer === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'configserver') + + function setConfigurationFiles({ model, getValue }) { + const value = getValue(model, '/resources/secret_config/data/mongod.conf') + return atob(value) } - if (configSrcMongos === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'mongos') + + function setConfigurationFilesShard({ model, getValue }) { + const value = getValue(model, '/resources/secret_shard_config/data/mongod.conf') + return atob(value) } -} -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/mongod.conf') -} + function setConfigurationFilesConfigServer({ model, getValue }) { + const value = getValue(model, '/resources/secret_configserver_config/data/mongod.conf') + return atob(value) + } -function setConfigurationShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/stringData/mongod.conf') - return value -} + function setConfigurationFilesMongos({ model, getValue }) { + const value = getValue(model, '/resources/secret_mongos_config/data/mongod.conf') + return atob(value) + } -function setConfigurationConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/stringData/mongod.conf') - return value -} + function onSetCustomConfigChange({ discriminator, getValue, commit }) { + const value = getValue(discriminator, '/setCustomConfig') -function setConfigurationMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/stringData/mongod.conf') - return value -} + if (value === 'no') { + commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/configSecret') + commit( + 'wizard/model$delete', + '/resources/kubedbComMongoDB/spec/shardTopology/shard/configSecret', + ) + commit( + 'wizard/model$delete', + '/resources/kubedbComMongoDB/spec/shardTopology/configServer/configSecret', + ) + commit( + 'wizard/model$delete', + '/resources/kubedbComMongoDB/spec/shardTopology/mongos/configSecret', + ) + commit('wizard/model$delete', '/resources/secret_config') + commit('wizard/model$delete', '/resources/secret_shard_config') + commit('wizard/model$delete', '/resources/secret_configserver_config') + commit('wizard/model$delete', '/resources/secret_mongos_config') + } + } -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/mongod.conf') - return atob(value) -} + function getCreateNameSpaceUrl({ storeGet }) { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setConfigurationFilesShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/data/mongod.conf') - return atob(value) -} + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } + } -function setConfigurationFilesConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/data/mongod.conf') - return atob(value) -} + function isVariantAvailable({ storeGet }) { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } -function setConfigurationFilesMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/data/mongod.conf') - return atob(value) -} + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') + //////////////////// Autoscaler ///////////////// - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComMongoDB/spec/configSecret') - commit( - 'wizard/model$delete', - '/resources/kubedbComMongoDB/spec/shardTopology/shard/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComMongoDB/spec/shardTopology/configServer/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComMongoDB/spec/shardTopology/mongos/configSecret', + let autoscaleType = '' + let dbDetails = {} + function isKubedb() { + return !!storeGet('/route/params/actions') + } + + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/spec/databaseRef/name') + return ( + !!getValue(model, '/spec/databaseRef/name') && !!getValue(discriminator, '/autoscalingType') ) - commit('wizard/model$delete', '/resources/secret_config') - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') } -} -function getCreateNameSpaceUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } -} + const namespace = + storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') || '' -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mongodbs/${name}`, + ) + dbDetails = resp.data || {} -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } + + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, + }) + } -//////////////////// Autoscaler ///////////////// + function mongoTypeEqualsTo(mongoType, type) { + // watchDependency('discriminator#/dbDetails') + autoscaleType = type + const dbDetailsSuccess = getValue(discriminator, '/dbDetails') -let autoscaleType = '' -let dbDetails = {} -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} + if (!dbDetailsSuccess) return false -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/spec/databaseRef/name') - return ( - !!getValue(model, '/spec/databaseRef/name') && !!getValue(discriminator, '/autoscalingType') - ) -} + const { spec } = dbDetails || {} + const { shardTopology, replicaSet } = spec || {} + let verd = '' + if (shardTopology) verd = 'sharded' + else { + if (replicaSet) verd = 'replicaSet' + else verd = 'standalone' + } + clearSpecModel(verd) + return mongoType === verd + } + + function clearSpecModel(dbtype) { + if (dbtype === 'standalone') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/replicaSet`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/shard`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/mongos`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/configServer`, + ) + } else if (dbtype === 'replicaSet') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/standalone`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/shard`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/mongos`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/configServer`, + ) + } else if (dbtype === 'sharded') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/standalone`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/replicaSet`, + ) + } + } + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComMongoDB/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -async function getDbDetails({ axios, storeGet, getValue, model, setDiscriminatorValue, commit }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') - const namespace = - storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') || '' + if (!configMapName) return [] - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mongodbs/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) + const configMaps = (resp && resp.data && resp.data.data) || {} + + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) + + return configMapKeys } catch (e) { console.log(e) + return [] } } - - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function mongoTypeEqualsTo( - { watchDependency, getValue, commit, discriminator }, - mongoType, - type, -) { - watchDependency('discriminator#/dbDetails') - autoscaleType = type - const dbDetailsSuccess = getValue(discriminator, '/dbDetails') - - if (!dbDetailsSuccess) return false - - const { spec } = dbDetails || {} - const { shardTopology, replicaSet } = spec || {} - let verd = '' - if (shardTopology) verd = 'sharded' - else { - if (replicaSet) verd = 'replicaSet' - else verd = 'standalone' - } - clearSpecModel({ commit }, verd) - return mongoType === verd -} - -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/replicaSet`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/shard`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/mongos`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/configServer`, - ) - } else if (dbtype === 'replicaSet') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/shard`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/mongos`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/configServer`, - ) - } else if (dbtype === 'sharded') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${autoscaleType}/replicaSet`, - ) + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] } -} -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComMongoDBAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComMongoDBAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComMongoDBAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComMongoDBAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} -function setMetadata({ storeGet, mode, commit }) { - const dbname = storeGet('/route/params/name') || '' - const namespace = storeGet('/route/query/namespace') || '' - if (mode === 'standalone-step') { - commit('wizard/model$update', { - path: '/metadata/release/name', - value: dbname, - force: true, - }) + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/${type}/controlledResources` commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, + path: path, + value: list, force: true, }) + return list } -} -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } + + function setApplyToIfReady() { + return 'IfReady' + } + + function setMetadata() { + const dbname = storeGet('/route/params/name') || '' + const namespace = storeGet('/route/query/namespace') || '' + const isKube = !!storeGet('/route/params/actions') + if (isKube) { commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, + path: '/metadata/release/name', + value: dbname, force: true, }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, + path: '/metadata/release/namespace', + value: namespace, force: true, }) } } -} -function objectCopy(obj) { - const temp = JSON.stringify(obj) - return JSON.parse(temp) -} + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } + } + } -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComMongoDBBinding') - return isExposeBinding -} + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } -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 labels = getValue(model, '/resources/kubedbComMongoDB/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'MongoDBBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComMongoDBBinding') + return isExposeBinding + } + + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComMongoDB/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'MongoDBBinding', + metadata: { + labels, 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') + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComMongoDBBinding', + value: bindingValues, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComMongoDBBinding') + } } -} -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mongodbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + const isKube = !!storeGet('/route/params/actions') - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mongodbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } + + async function fetchTopologyMachines() { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] + + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) + + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + // return nodeGroups + } catch (e) { + console.log(e) + // return [] + setDiscriminatorValue('/topologyMachines', []) + } + } + } - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + function setAllowedMachine(type, minmax) { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) } catch (e) { console.log(e) - return [] + parsedInstance = {} } - } -} -function setAllowedMachine({ model, getValue }, type, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + const machine = parsedInstance[type] || '' + const mx = machine?.includes(',') ? machine.split(',')[1] : '' + const mn = machine?.includes(',') ? machine.split(',')[0] : '' + + if (minmax === 'min') return mn + else return mx } - const machine = parsedInstance[type] || '' - const mx = machine?.includes(',') ? machine.split(',')[1] : '' - const mn = machine?.includes(',') ? machine.split(',')[0] : '' + function getMachines(type, minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${type}-${depends}` - if (minmax === 'min') return mn - else return mx -} + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) -async function getMachines({ getValue, watchDependency, discriminator }, type, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${type}-${depends}` + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) + return dependantIndex === -1 ? machines : filteredMachine + } - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) + function hasAnnotations() { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] - return dependantIndex === -1 ? machines : filteredMachine -} + return !!instance + } -function hasAnnotations({ model, getValue }, type) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + function hasNoAnnotations() { + return !hasAnnotations() + } - return !!instance -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} + const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) + const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) + const minMaxMachine = `${minMachine},${maxMachine}` -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComMongoDBAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - - const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) - const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) - const minMaxMachine = `${minMachine},${maxMachine}` - - parsedInstance[type] = minMaxMachine - const instanceString = JSON.stringify(parsedInstance) - annotations['kubernetes.io/instance-type'] = instanceString - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== instanceString) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + parsedInstance[type] = minMaxMachine + const instanceString = JSON.stringify(parsedInstance) + annotations['kubernetes.io/instance-type'] = instanceString + + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComMongoDBAutoscaler/spec/compute/${type}` + + if (minMachine && maxMachine && instance !== instanceString) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: annotations, + force: true, + }) + } + } + + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } } -} -return { - getOpsRequestUrl, - handleUnit, - setMetadata, - isKubedb, - getDbDetails, - mongoTypeEqualsTo, - clearSpecModel, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - isRancherManaged, - fetchNamespaces, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - isBlueprintOption, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - isNotShardModeSelected, - isShardModeSelected, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - getMongoDbVersions, - showAuthPasswordField, - showAuthSecretField, - showNewSecretCreateField, - isNotStandaloneMode, - showCommonStorageClassAndSizeField, - setDatabaseMode, - getStorageClassNames, - setStorageClass, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComMongDbAnnotation, - addKubeDbComMongDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfigurationSourceShard, - setConfigurationSourceConfigServer, - setConfigurationSourceMongos, - isSchemaOf, - disableConfigSourceOption, - onConfigurationSourceMongosChange, - onConfigurationSourceShardChange, - onConfigurationSourceConfigServerChange, - transferConfigSecret, - onConfigSecretModelChange, - setConfiguration, - setConfigurationShard, - setConfigurationConfigServer, - setConfigurationMongos, - setConfigurationFiles, - setConfigurationFilesShard, - setConfigurationFilesConfigServer, - setConfigurationFilesMongos, - onSetCustomConfigChange, - getCreateNameSpaceUrl, - updateConfigServerStorageClass, - - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - getNamespaceArray, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + return { + getOpsRequestUrl, + handleUnit, + setMetadata, + isKubedb, + getDbDetails, + mongoTypeEqualsTo, + clearSpecModel, + fetchNodeTopology, + isNodeTopologySelected, + setControlledResources, + setTrigger, + setApplyToIfReady, + showOpsRequestOptions, + setInitSchedule, + fetchNames, + isRancherManaged, + fetchNamespaces, + onInputChangeSchedule, + getDefaultSchedule, + getBlueprints, + ifUsagePolicy, + isBlueprintOption, + getDefault, + onInputChange, + showBackupOptions, + showScheduleBackup, + isVariantAvailable, + fetchJsons, + disableLableChecker, + isEqualToModelPathValue, + getResources, + isEqualToDiscriminatorPath, + setValueFromModel, + isNotShardModeSelected, + isShardModeSelected, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + returnTrue, + returnStringYes, + getMongoDbVersions, + showAuthPasswordField, + showAuthSecretField, + showNewSecretCreateField, + isNotStandaloneMode, + showCommonStorageClassAndSizeField, + setDatabaseMode, + getStorageClassNames, + setStorageClass, + deleteDatabaseModePath, + isEqualToDatabaseMode, + setApiGroup, + getIssuerRefsName, + hasIssuerRefName, + hasNoIssuerRefName, + setClusterAuthMode, + setSSLMode, + showTlsConfigureSection, + onTlsConfigureChange, + getAliasOptions, + showMonitoringSection, + onEnableMonitoringChange, + showCustomizeExporterSection, + onCustomizeExporterChange, + disableInitializationSection, + valueExists, + initPrePopulateDatabase, + onPrePopulateDatabaseChange, + initDataSource, + onDataSourceChange, + initVolumeType, + onVolumeTypeChange, + showInitializationForm, + showScriptOrStashForm, + showConfigMapOrSecretName, + initializeNamespace, + showRepositorySelectOrCreate, + onInitRepositoryChoiseChange, + initCustomizeRestoreJobRuntimeSettings, + initCustomizeRestoreJobRuntimeSettingsForBackup, + onCustomizeRestoreJobRuntimeSettingsChange, + onCustomizeRestoreJobRuntimeSettingsChangeForBackup, + showRuntimeForm, + getImagePullSecrets, + getBackupConfigsAndAnnotations, + deleteKubeDbComMongDbAnnotation, + addKubeDbComMongDbAnnotation, + initScheduleBackup, + initScheduleBackupForEdit, + onScheduleBackupChange, + showBackupForm, + initalizeTargetReferenceName, + setInitialRestoreSessionRepo, + initRepositoryChoise, + initRepositoryChoiseForEdit, + onRepositoryChoiseChange, + onRepositoryNameChange, + getMongoAnnotations, + initFromAnnotationValue, + onBackupBlueprintNameChange, + onBackupBlueprintScheduleChange, + initFromAnnotationKeyValue, + onTaskParametersChange, + isValueExistInModel, + onNamespaceChange, + onLabelChange, + onNameChange, + returnFalse, + onAgentChange, + getCreateAuthSecret, + showExistingSecretSection, + showPasswordSection, + setAuthSecretPassword, + onAuthSecretPasswordChange, + encodePassword, + decodePassword, + onCreateAuthSecretChange, + getSecrets, + isEqualToServiceMonitorType, + onConfigurationSourceChange, + onConfigurationChange, + setConfigurationSource, + setSecretConfigNamespace, + setConfigurationSourceShard, + setConfigurationSourceConfigServer, + setConfigurationSourceMongos, + isSchemaOf, + disableConfigSourceOption, + onConfigurationSourceMongosChange, + onConfigurationSourceShardChange, + onConfigurationSourceConfigServerChange, + transferConfigSecret, + onConfigSecretModelChange, + setConfiguration, + setConfigurationShard, + setConfigurationConfigServer, + setConfigurationMongos, + setConfigurationFiles, + setConfigurationFilesShard, + setConfigurationFilesConfigServer, + setConfigurationFilesMongos, + onSetCustomConfigChange, + getCreateNameSpaceUrl, + updateConfigServerStorageClass, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + getNamespaceArray, + isBackupType, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showSchedule, + showConfigList, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + onBackupTypeChange, + isBindingAlreadyOn, + addOrRemoveBinding, + getMachines, + setAllowedMachine, + hasAnnotations, + hasNoAnnotations, + fetchTopologyMachines, + onMachineChange, + isEqualToValueFromType, + onValueFromChange, + getConfigMapKeys, + setValueFrom, + isInputTypeValueFrom, + getSecretKeys, + } } diff --git a/charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml b/charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml index 0ffc233716..3faa129c71 100644 --- a/charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml @@ -1,403 +1,381 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - customPid: - type: string - pid: - type: string - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/MSSQLServer/versions - if: isToggleOn|databases/MSSQLServer/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/MSSQLServer/properties/versions/properties/default - type: select - - computed: getDefault|databases/MSSQLServer/mode - fetch: getAdminOptions|databases/MSSQLServer/mode - hasDescription: true - if: isToggleOn|databases/MSSQLServer/mode - label: - text: labels.database.mode - onChange: onModeChange - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - element: - label: - text: labels.databases - type: input - if: isEqualToModelPathValue|Topology|/spec/mode - label: - text: labels.availabilityGroup - schema: - $ref: schema#/properties/spec/properties/topology/properties/availabilityGroup/properties/databases - type: list-input-form - - if: isEqualToModelPathValue|Topology|/spec/mode - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/MSSQLServer/versions + if: + type: function + name: isToggleOn|databases/MSSQLServer/versions + label: Database version + schema: schema/properties/spec/properties/admin/properties/databases/properties/MSSQLServer/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/MSSQLServer/mode + loader: getAdminOptions|databases/MSSQLServer/mode + if: + type: function + name: isToggleOn|databases/MSSQLServer/mode + label: Database mode + isHorizontal: true + watcher: + func: onModeChange + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - type: array-item-form + element: + label: Databases type: input - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + schema: schema/properties/spec/properties/topology/properties/availabilityGroup/properties/databases + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Availability Group + schema: schema/properties/spec/properties/topology/properties/availabilityGroup/properties/databases + - if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Replicaset number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - if: showStorageSizeField - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - init: + type: func + value: setLimits|cpu + if: + type: function + name: isMachineCustom + label: cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input + - init: + type: func + value: setLimits|memory + if: + type: function + name: isMachineCustom + label: memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine_profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: showStorageSizeField + label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - elements: + - loader: getAdminOptions|clusterIssuers + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default + type: select + type: block-layout + - label: Accept EULA? + schema: schema/properties/spec/properties/acceptEULA + type: switch + - init: + type: func + value: getDefaulPid + label: PID + watcher: + func: onPidChange + paths: + - temp/pid + options: + - Developer + - Express + - Standard + - Evaluation + - Enterprise + - EnterpriseCore + - Custom + validation: + type: required + schema: temp/pid + type: select + - if: + type: function + name: isPidCustom + label: Custom PID + watcher: + func: onCustomPidChange + paths: + - temp/customPid + validation: + type: required + schema: temp/customPid + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - fetch: getAdminOptions|clusterIssuers - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - label: - text: Accept EULA? - schema: - $ref: schema#/properties/spec/properties/acceptEULA - type: switch - - computed: getDefaulPid - label: - text: PID - onChange: onPidChange + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy options: - - Developer - - Express - - Standard - - Evaluation - - Enterprise - - EnterpriseCore - - Custom - required: true - schema: - $ref: discriminator#/properties/pid + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name type: select - - if: isPidCustom - label: - text: Custom PID - onChange: onCustomPidChange - required: true - schema: - $ref: discriminator#/properties/customPid + - if: + type: function + name: showReferSecret + label: password + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - recovery: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + # hasCopy: true + schema: schema/properties/spec/properties/configuration + type: textarea + - init: + type: func + value: getDefault|pointInTimeRecovery + if: + type: function + name: isToggleOn|pointInTimeRecovery + label: Point in-time Recovery? + schema: temp/recovery + type: switch + - elements: + - label: Namespace + watcher: + func: setPointInTimeRecovery + paths: + - temp/refNamespace + validation: + type: required + schema: temp/refNamespace type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - computed: getDefault|pointInTimeRecovery - if: isToggleOn|pointInTimeRecovery - label: - text: Point in-time Recovery? - schema: - $ref: discriminator#/recovery + - label: Name + watcher: + func: setPointInTimeRecovery + paths: + - temp/refDBName + validation: + type: required + schema: temp/refDBName + type: input + - customClass: mt-10 + label: Recovery Timestamp + schema: schema/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp + type: input + if: + type: function + name: showRecovery + label: Point in-time Recovery + showLabels: true + type: block-layout + - if: + type: function + name: isToggleOn|deployment + label: Deployment name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + if: + type: function + name: isToggleOn|monitoring + label: Enable Monitoring? + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - discriminator: - refDBName: - type: string - refNamespace: - type: string - elements: - - label: - text: Namespace - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refNamespace - type: input - - label: - text: Name - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refDBName - type: input - - customClass: mt-10 - label: - text: Recovery Timestamp - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp - type: input - if: showRecovery - label: - text: Point in-time Recovery - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver - show_label: true - type: single-step-form - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - if: isToggleOn|monitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - disable: showArchiverAlert + label: Enable Archiver? + watcher: + func: onArchiverChange + paths: + - schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default + schema: schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch - - elements: - - disabled: showArchiverAlert - label: - text: Enable Archiver? - onChange: onArchiverChange - schema: - $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default - type: switch - - alertInfo: - show: true - type: neutral - if: showArchiverAlert - label: - text: The selected StorageClass does not support Archiver - type: label-element - if: showArchiver - type: single-step-form - - if: isToggleOn|tls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default + - if: + type: function + name: showArchiverAlert + label: The selected StorageClass does not support Archiver + type: warning + if: + type: function + name: showArchiver + type: block-layout + - if: + type: function + name: isToggleOn|tls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default + type: switch + - elements: + - label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - if: isToggleOn|expose - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|expose + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-mssqlserver-editor-options/ui/functions.js b/charts/kubedbcom-mssqlserver-editor-options/ui/functions.js index 3eb7a4f152..729d7e49d9 100644 --- a/charts/kubedbcom-mssqlserver-editor-options/ui/functions.js +++ b/charts/kubedbcom-mssqlserver-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1096 +317,1120 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Standalone', 'Topology'] - return validType.includes(modelPathValue) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('customPid', '') + setDiscriminatorValue('pid', '') + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('recovery', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('refDBName', '') + setDiscriminatorValue('refNamespace', '') + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function onModeChange({ model, getValue, commit }) { - const dbMode = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/replicas', - value: dbMode === 'Topology' ? 3 : 1, - force: true, - }) -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Standalone', 'Topology'] + return validType.includes(modelPathValue) + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + function onModeChange() { + const dbMode = getValue(model, '/spec/mode') + commit('wizard/model$update', { + path: '/spec/replicas', + value: dbMode === 'Topology' ? 3 : 1, + force: true, }) - } else { - array = machineList - .map((machine) => { + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) - commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: commitPath, + value: val, force: true, }) - commit('wizard/model$update', { - path: comparePath, - value: cpu, - force: true, - }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} - -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + if (val === 'capz' && ifDedicated()) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - const projects = resp?.data?.status?.projects - if (projects) { - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - namespaces = projectsNamespace + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] } else { - namespaces = resp?.data?.status?.namespaces || [] + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] } - return namespaces - } catch (e) { - console.log(e) - return [] - } -} - -function showRecovery({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/recovery') - const isRecoveryOn = getValue(discriminator, '/recovery') || '' - return isRecoveryOn -} -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} - -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') - - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') - } -} - -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} - -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} - -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} - -function updateAlertValue({ commit, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} - -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} - -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} - -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -let namespaces = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - if (!getValue(model, `/spec/admin/databases/MSSQLServer/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/MSSQLServer/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/MSSQLServer/mode/available') || [] - if (arr.length) defMode = arr[0] + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + const projects = resp?.data?.status?.projects + if (projects) { + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + namespaces = projectsNamespace + } else { + namespaces = resp?.data?.status?.namespaces || [] + } + return namespaces + } catch (e) { + console.log(e) + return [] } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) + function showRecovery() { + // watchDependency('discriminator#/recovery') + const isRecoveryOn = getValue(discriminator, '/recovery') || '' + return isRecoveryOn } - if (!features.includes('binding')) { + + function onAuthChange() { commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, + path: '/spec/authSecret/name', + value: '', force: true, }) - } - if (!features.includes('monitoring')) { commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', + path: '/spec/authSecret/password', value: '', force: true, }) + } + + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') + + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } + + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } + + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } + + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { path: '/form/alert/enabled', - value: 'none', + value: alert, force: true, }) - } - if (!features.includes('backup')) { + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) + } + + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } + + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } + + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { path: '/spec/backup/tool', - value: '', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - namespaces = getNamespaces({ axios, storeGet }) - setDiscriminatorValue('/bundleApiLoaded', true) -} -function fetchNamespaces({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return namespaces -} + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let namespaces = [] + + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` -async function getRecoveryNames({ getValue, model, watchDependency, storeGet, axios }, type) { - watchDependency(`model#/spec/init/archiver/${type}/namespace`) - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` - if (type === 'encryptionSecret') - url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - const options = [] - if (namespace) { try { const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } } catch (e) { console.log(e) } - } - return options -} -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } - - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) + + if (!getValue(model, `/spec/admin/databases/MSSQLServer/mode/toggle`)) { + let defMode = getDefault('databases/MSSQLServer/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/MSSQLServer/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } + + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } + namespaces = getNamespaces() + setDiscriminatorValue('/bundleApiLoaded', true) } - return returnArray -} + function fetchNamespaces() { + // watchDependency('discriminator#/bundleApiLoaded') + return namespaces + } -let archiverMap = [] -let archiverCalled = false + async function getRecoveryNames(type) { + // watchDependency(`model#/spec/init/archiver/${type}/namespace`) + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` + if (type === 'encryptionSecret') + url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + const options = [] + if (namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + } + return options + } -function getAdminOptions({ getValue, model, watchDependency, axios, storeGet, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } - if (type === 'storageClasses' && !archiverCalled) { - getArchiverName({ axios, storeGet }) + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } + + return returnArray } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + let archiverMap = [] + let archiverCalled = false + + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') + + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName() + } + + const options = getValue(model, `/spec/admin/${type}/available`) || [] - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + + function showArchiver() { + return checkIfFeatureOn('archiver') } - return options -} -function showArchiver({ getValue, model }) { - return checkIfFeatureOn({ getValue, model }, 'archiver') -} + async function getArchiverName() { + 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) -async function getArchiverName({ axios, storeGet }) { - 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) + 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') + function onArchiverChange() { + 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) - const via = getValue(model, '/spec/admin/archiver/via') + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const via = getValue(model, '/spec/admin/archiver/via') - if (!isArchiverOn) { - commit('wizard/model$update', { - path: '/spec/archiverName', - value: '', - force: true, - }) - } else { - if (via === 'VolumeSnapshotter') { + if (!isArchiverOn) { commit('wizard/model$update', { path: '/spec/archiverName', - value: found.annotation, + value: '', force: true, }) } else { - const kind = getValue(model, '/metadata/resource/kind') - commit('wizard/model$update', { - path: '/spec/archiverName', - value: kind.toLowerCase(), - force: true, - }) + if (via === 'VolumeSnapshotter') { + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) + } else { + const kind = getValue(model, '/metadata/resource/kind') + commit('wizard/model$update', { + path: '/spec/archiverName', + value: kind.toLowerCase(), + force: true, + }) + } } } -} -function showArchiverAlert({ watchDependency, model, getValue, commit }) { - watchDependency('model#/spec/admin/storageClasses/default') + function showArchiverAlert() { + // watchDependency('model#/spec/admin/storageClasses/default') - const mode = getValue(model, '/spec/mode') - if (mode === 'Standalone') return false + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false - const via = getValue(model, '/spec/admin/archiver/via') - - if (via === 'VolumeSnapshotter') { - // toggle archiver to false when storageClass annotation not found - const stClass = getValue(model, '/spec/admin/storageClasses/default') - const found = archiverMap.find((item) => item.storageClass === stClass) - const show = !found?.annotation - if (show) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - return true - } else onArchiverChange({ model, getValue, commit }) - } else onArchiverChange({ model, getValue, commit }) - return false -} + const via = getValue(model, '/spec/admin/archiver/via') -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + if (via === 'VolumeSnapshotter') { + // toggle archiver to false when storageClass annotation not found + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + if (show) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return true + } else onArchiverChange() + } else onArchiverChange() + return false } - const backupVal = getValue(model, '/spec/backup/tool') - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && val + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } } -} -function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) - } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} - -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function returnFalse() { + return false + } -function getDefaulPid({ getValue, model }) { - return (pid = getValue(model, '/spec/pid') || '') -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function onPidChange({ getValue, discriminator, commit }) { - const pid = getValue(discriminator, '/pid') - commit('wizard/model$update', { - path: '/spec/pid', - value: pid !== 'Custom' ? pid : '', - force: true, - }) -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function isPidCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/pid') - const pid = getValue(discriminator, '/pid') - return pid === 'Custom' -} + function getDefaulPid() { + return (pid = getValue(model, '/spec/pid') || '') + } -function onCustomPidChange({ getValue, discriminator, commit }) { - const customPid = getValue(discriminator, '/customPid') - commit('wizard/model$update', { - path: '/spec/pid', - value: customPid, - force: true, - }) -} + function onPidChange() { + const pid = getValue(discriminator, '/pid') + commit('wizard/model$update', { + path: '/spec/pid', + value: pid !== 'Custom' ? pid : '', + force: true, + }) + } -function convertToLocal(input) { - const date = new Date(input) + function isPidCustom() { + // watchDependency('discriminator#/pid') + const pid = getValue(discriminator, '/pid') + return pid === 'Custom' + } - if (isNaN(date.getTime())) { - return null + function onCustomPidChange() { + const customPid = getValue(discriminator, '/customPid') + commit('wizard/model$update', { + path: '/spec/pid', + value: customPid, + force: true, + }) } - return date.toString() -} + function convertToLocal(input) { + const date = new Date(input) -function getComponentLogStats(snapshot) { - if (!snapshot || !snapshot.status || !snapshot.status.components) { - return null + if (isNaN(date.getTime())) { + return null + } + + return date.toString() } - const components = snapshot.status.components - const appKind = snapshot.spec?.appRef?.kind + function getComponentLogStats(snapshot) { + if (!snapshot || !snapshot.status || !snapshot.status.components) { + return null + } + + const components = snapshot.status.components + const appKind = snapshot.spec?.appRef?.kind - if (appKind === 'MongoDB') { - for (const [key, value] of Object.entries(components)) { - if (key.endsWith('0') && value.logStats) { - return value.logStats + if (appKind === 'MongoDB') { + for (const [key, value] of Object.entries(components)) { + if (key.endsWith('0') && value.logStats) { + return value.logStats + } } } - } - if (components['wal'] && components['wal'].logStats) { - return components['wal'].logStats - } + if (components['wal'] && components['wal'].logStats) { + return components['wal'].logStats + } - return null -} + return null + } -async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const refNamespace = getValue(discriminator, '/refNamespace') - const refDBName = getValue(discriminator, '/refDBName') + async function setPointInTimeRecovery() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const refNamespace = getValue(discriminator, '/refNamespace') + const refDBName = getValue(discriminator, '/refDBName') - try { - const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` - const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` - const repositoriesResp = await axios.get(repositoriesUrl) - const snapshotsResp = await axios.get(snapshotsUrl) + try { + const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` + const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` + const repositoriesResp = await axios.get(repositoriesUrl) + const snapshotsResp = await axios.get(snapshotsUrl) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/name`, - value: repositoriesResp.data?.spec.encryptionSecret.name, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/namespace`, - value: repositoriesResp.data?.spec.encryptionSecret.namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/name`, - value: `${refDBName}-full`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/name`, - value: `${refDBName}-manifest`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/name`, + value: repositoriesResp.data?.spec.encryptionSecret.name, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/namespace`, + value: repositoriesResp.data?.spec.encryptionSecret.namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/name`, + value: `${refDBName}-full`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/name`, + value: `${refDBName}-manifest`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) - const resp = getComponentLogStats(snapshotsResp.data) + const resp = getComponentLogStats(snapshotsResp.data) - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: convertToLocal(resp?.end), - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: convertToLocal(resp?.start), - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: convertToLocal(resp?.end), - force: true, - }) - } catch (e) { - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: '', - force: true, - }) - console.log(e) + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: convertToLocal(resp?.end), + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: convertToLocal(resp?.start), + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: convertToLocal(resp?.end), + force: true, + }) + } catch (e) { + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: '', + force: true, + }) + console.log(e) + } } -} -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} - -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - setPointInTimeRecovery, - getRecoveryNames, - fetchNamespaces, - showRecovery, - showAdditionalSettings, - initBundle, - returnFalse, - isVariantAvailable, - showAuthPasswordField, - isEqualToModelPathValue, - showStorageSizeField, - onModeChange, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - getNamespaces, - isToggleOn, - getAdminOptions, - getNodeTopology, - isMachineNotCustom, - isMachineCustom, - onAuthChange, - clearConfiguration, - isConfigDatabaseOn, - showIssuer, - setMonitoring, - showAlerts, - onBackupSwitch, - updateAlertValue, - setBackup, - getDefault, - getDefaulPid, - onPidChange, - isPidCustom, - onCustomPidChange, - onArchiverChange, - showArchiverAlert, - showArchiver, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + setPointInTimeRecovery, + getRecoveryNames, + fetchNamespaces, + showRecovery, + showAdditionalSettings, + initBundle, + returnFalse, + isVariantAvailable, + showAuthPasswordField, + isEqualToModelPathValue, + showStorageSizeField, + onModeChange, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + getNamespaces, + isToggleOn, + getAdminOptions, + getNodeTopology, + isMachineNotCustom, + isMachineCustom, + onAuthChange, + clearConfiguration, + isConfigDatabaseOn, + showIssuer, + setMonitoring, + showAlerts, + onBackupSwitch, + updateAlertValue, + setBackup, + getDefault, + getDefaulPid, + onPidChange, + isPidCustom, + onCustomPidChange, + onArchiverChange, + showArchiverAlert, + showArchiver, + filterNodeTopology, + } } diff --git a/charts/kubedbcom-mssqlserver-editor/ui/edit-ui.yaml b/charts/kubedbcom-mssqlserver-editor/ui/edit-ui.yaml index 6db7f4c9a6..c216a02e7c 100644 --- a/charts/kubedbcom-mssqlserver-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-mssqlserver-editor/ui/edit-ui.yaml @@ -1,758 +1,654 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - discriminator: - repoInitialSelectionStatus: - type: string - scheduleBackup: - default: "yes" - type: string +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - computed: initScheduleBackupForEdit - if: showScheduleBackup - label: - text: labels.backup.title - onChange: onScheduleBackupChange + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/scheduleBackup - type: radio - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string - elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true + options: + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig + elements: + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails + elements: + - type: block-layout + if: + type: function + name: isConsole elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType + options: + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - if: showBackupForm - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.4.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + # mssqlserver mode + - type: block-layout + label: MSSQLServer + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/mssqlserver/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|mssqlserver + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|mssqlserver + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|mssqlserver + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: block-layout + showLabels: false elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/mssqlserver/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string + - type: block-layout + showLabels: false elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|mssqlserver - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|mssqlserver - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|mssqlserver - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver/properties/controlledResources - type: multiselect - label: - text: MSSQLServer - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: block-layout + label: MSSQLServer + showLabels: true + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMSSQLServerAutoscaler/spec/storage/mssqlserver/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComMSSQLServer/spec/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComMSSQLServerAutoscaler/spec/storage/mssqlserver/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComMSSQLServerAutoscaler/spec/storage/mssqlserver/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - computed: getDbDetails - if: returnFalse - type: input - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComMSSQLServerAutoscaler/spec/storage/mssqlserver/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/trigger - type: select - - label: - text: Expansion Mode + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComMSSQLServer/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection + elements: + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMSSQLServer/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMSSQLServer/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComMSSQLServerAutoscaler/spec/storage/mssqlserver/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComMSSQLServerAutoscaler/spec/storage/mssqlserver/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/storage/properties/mssqlserver/properties/upperBound - type: input - label: - text: MSSQLServer - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/compute/properties/mssqlserver - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMSSQLServerAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.7.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComMSSQLServer/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMSSQLServer/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMSSQLServer/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMSSQLServer/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMSSQLServer/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -type: multi-step-form + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMSSQLServer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true \ No newline at end of file diff --git a/charts/kubedbcom-mssqlserver-editor/ui/functions.js b/charts/kubedbcom-mssqlserver-editor/ui/functions.js index 63652ca563..1555690730 100644 --- a/charts/kubedbcom-mssqlserver-editor/ui/functions.js +++ b/charts/kubedbcom-mssqlserver-editor/ui/functions.js @@ -1,3296 +1,1446 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + + initRepositoryChoiseForEdit() + + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function initScheduleBackup() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) + + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } -} -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + function onScheduleBackupChange() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + if (scheduleBackup === 'no') { + // delete stashAppscodeComBackupConfiguration + commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + // delete annotation from kubedbComMSSQLServer annotation + deleteKubeDbComMSSQLServerDbAnnotation(getValue, model, commit) + } else { + const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // create stashAppscodeComBackupConfiguration and initialize it if not exists - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + const dbName = getValue(model, '/metadata/release/name') - const resources = (resp && resp.data && resp.data.items) || [] + if ( + !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && + !isBluePrint + ) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration', + value: stashAppscodeComBackupConfiguration, + }) + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + } + } + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false } -} -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} + function deleteKubeDbComMSSQLServerDbAnnotation(getValue, model, commit) { + const annotations = + getValue(model, '/resources/kubedbComMSSQLServer/metadata/annotations') || {} + const filteredKeyList = + Object.keys(annotations).filter( + (k) => + k !== 'stash.appscode.com/backup-blueprint' && + k !== 'stash.appscode.com/schedule' && + !k.startsWith('params.stash.appscode.com/'), + ) || [] + const filteredAnnotations = {} + filteredKeyList.forEach((k) => { + filteredAnnotations[k] = annotations[k] + }) + commit('wizard/model$update', { + path: '/resources/kubedbComMSSQLServer/metadata/annotations', + value: filteredAnnotations, + }) + } -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + function getBackupConfigsAndAnnotations(getValue, model) { + const stashAppscodeComBackupConfiguration = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration', + ) -function isNotShardModeSelected({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComMSSQLServer/spec') - const hasShardTopology = getValue(model, '/resources/kubedbComMSSQLServer/spec/shardTopology') - return !hasShardTopology -} + const coreKubestashComBackupConfiguration = getValue( + model, + '/resources/coreKubestashComBackupConfiguration', + ) + const kubeStashTarget = coreKubestashComBackupConfiguration?.spec?.target -function isShardModeSelected({ model, getValue, watchDependency, commit }) { - const resp = !isNotShardModeSelected({ model, getValue, watchDependency }) - if (resp) { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - } - return resp -} + const mongoDB = getValue(model, '/resources/kubedbComMSSQLServer') + const mongoDbKind = mongoDB?.apiVersion?.split('/')?.at(0) -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + let isKubeStash = false + if ( + mongoDB?.kind === kubeStashTarget?.kind && + mongoDB?.metadata?.name === kubeStashTarget?.name && + mongoDB?.metadata?.namespace === kubeStashTarget?.namespace && + mongoDbKind === kubeStashTarget?.apiGroup + ) { + isKubeStash = true + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const kubedbComMSSQLServerAnnotations = + getValue(model, '/resources/kubedbComMSSQLServer/metadata/annotations') || {} - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const isBluePrint = Object.keys(kubedbComMSSQLServerAnnotations).some( + (k) => + k === 'stash.appscode.com/backup-blueprint' || + k === 'stash.appscode.com/schedule' || + k.startsWith('params.stash.appscode.com/'), + ) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return { + stashAppscodeComBackupConfiguration, + isBluePrint, + isKubeStash, + } } - return ans -} + // backup form + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false + } -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let namespaceList = [] + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComMSSQLServer') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + // get values.yaml to populate data when backup-config is being created + try { + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - return ans -} + const resp = await axios.get(url) -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} + } catch (e) { + console.log(e) + } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + // check config with metadata name first + let config = configs?.find( + (item) => + item.metadata?.name === name && + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) -function returnTrue() { - return true -} + // set backup switch here + isBackupOn = !!config -function returnStringYes() { - return 'yes' -} + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset -// ************************* Basic Info ********************************************** -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions + } - const resources = (resp && resp.data && resp.data.items) || [] + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + setDiscriminatorValue('isBackupDataLoaded', true) + } - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') } -} -// ************************* Auth Secret Field ****************************************** -function showAuthPasswordField({ model, getValue, watchDependency }) { - watchDependency('model#/resources') - const modelPathValue = getValue(model, '/resources') - return !!( - modelPathValue && - modelPathValue.secret && - modelPathValue.secret.metadata && - modelPathValue.secret.metadata.name && - !showAuthSecretField({ model, getValue, watchDependency }) - ) -} + function setBackupType() { + return 'BackupConfig' + } -function showAuthSecretField({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComMSSQLServer/spec') - const modelPathValue = getValue(model, '/resources/kubedbComMSSQLServer/spec') - return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) -} + function getTypes() { + const arr = [ + { + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', + }, + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] + + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) + } + return arr + } -function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { - const resp = - !showAuthSecretField({ model, getValue, watchDependency }) && - !showAuthPasswordField({ model, getValue, watchDependency }) - const secret = getValue(model, '/resources/secret_auth') - if (resp && !secret) { + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') commit('wizard/model$update', { - path: '/resources/secret_auth', - value: { - data: { - password: '', - }, - }, + path: '/backupType', + value: type, + force: true, + }) + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), + force: true, + }) + } + commit('wizard/model$delete', '/context') + commit('wizard/model$update', { + path: '/resources/kubedbComMSSQLServer', + value: objectCopy(dbResource), force: true, }) } - return resp -} - -// ********************* Database Mode *********************** -function isNotStandaloneMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Standalone' -} -function showCommonStorageClassAndSizeField({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(mode) -} -function setDatabaseMode({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/resources/kubedbComMSSQLServer/spec') + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') - watchDependency('model#/resources/kubedbComMSSQLServer/spec') - if (modelPathValue.shardTopology) { - return 'Sharded' - } else if (modelPathValue.replicaSet) { - return 'Replicaset' - } else { - return 'Standalone' + return selectedType === type } -} - -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, model, getValue, watchDependency, discriminator }, - mode, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const databaseModeShard = getValue(discriminator, '/activeDatabaseMode') === 'Sharded' - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - storageClassList = resources - const path = - mode === 'shard' - ? '/resources/kubedbComMSSQLServer/spec/shardTopology/shard/storage/storageClassName' - : '/resources/kubedbComMSSQLServer/spec/storage/storageClassName' - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ getValue, commit, model, discriminator }) - return resources -} -function setStorageClass({ getValue, commit, model, discriminator }) { - const deletionPolicy = getValue(model, 'resources/kubedbComMSSQLServer/spec/deletionPolicy') || '' - const suffix = '-retain' - let storageClass = '' + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) + } - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') + if (blueprintSwitch) addLabelAnnotation('annotations') + else deleteLabelAnnotation('annotations') + } - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver + } - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComMSSQLServer/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + commit('wizard/model$delete', path) } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value + } + + function addLabelAnnotation(type) { + const obj = objectCopy(initialDbMetadata[type]) + + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + obj['kubedb.com/archiver'] = 'true' } + + commit('wizard/model$update', { + path: `/resources/kubedbComMSSQLServer/metadata/${type}`, + value: obj, + force: true, + }) } - const mode = getValue(discriminator, '/activeDatabaseMode') + function deleteLabelAnnotation(type) { + const obj = initialDbMetadata[type] + + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] - if (mode === 'Sharded') { commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/shard/storage/storageClassName', - value: storageClass, + path: `/resources/kubedbComMSSQLServer/metadata/${type}`, + value: obj, force: true, }) + } + + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } + + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, + path: '/context', + value: context, force: true, }) - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/storage') - } else { + if (context === 'Create') { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, + force: true, + }) + } + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) + } + + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) + const list = filteredList?.map((ele) => ele.metadata.name) + return list + } + + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) + commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/storage/storageClassName', - value: storageClass, + path: '/resources/coreKubestashComBackupConfiguration', + value: configDetails, force: true, }) } -} -function updateConfigServerStorageClass({ getValue, model, commit }) { - const storageClass = - getValue( - model, - '/resources/kubedbComMSSQLServer/spec/shardTopology/shard/storage/storageClassName', - ) || '' - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, - force: true, - }) -} + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' + } + + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' + } -function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - const modelSpec = getValue(model, '/resources/kubedbComMSSQLServer/spec') - if (mode === 'Sharded') { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/podTemplate') - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/configSecret') + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName + } + + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } + + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' + } + + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - commit('wizard/model$delete', '/resources/secret_config') + return repoInitialSelectionStatus + } - if (!modelSpec.shardTopology) { + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology', - value: { - configServer: { - replicas: 3, - storage: { - resources: { - requests: { - storage: '', - }, - }, - }, - }, - mongos: { - replicas: 2, - }, - shard: { - replicas: 3, - shards: 3, - storage: { - resources: { - requests: { - storage: '', - }, - }, - }, - }, + path: modelPath, + value: session, + }) + } + } + + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComMSSQLServer/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'MSSQLServerBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, }, + }, + } + + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComMSSQLServerBinding', + value: bindingValues, force: true, }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComMSSQLServerBinding') } - } else if (mode === 'Replicaset') { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/shardTopology') + } + + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComMSSQLServerBinding') + return isExposeBinding + } + + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } + + /************ Compute Autoscaling ************/ - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') + let autoscaleType = '' + let dbDetails = {} - if (!modelSpec.replicaSet) { + function isConsole() { + const isKube = isKubedb() + + if (isKube) { + const dbName = storeGet('/route/params/name') || '' commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/replicaSet', - value: { name: '' }, + path: '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', + value: dbName, force: true, }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/replicas', - value: 3, + path: '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/name', + value: modifiedName, force: true, }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } - } else if (mode === 'Standalone') { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/shardTopology') - - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/replicas') - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') + return !isKube } -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} - -// ************************** TLS ******************************88 -function setApiGroup() { - return 'cert-manager.io' -} + function isKubedb() { + return !!storeGet('/route/params/actions') + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComMSSQLServer/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComMSSQLServer/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComMSSQLServer/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComMSSQLServer/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue( + model, + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', + ) || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mssqlservers/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, + }) } - if (!url) return [] + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { - const resp = await axios.get(url) + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + return { + text: name, + value: name, + } }) - return resources - } catch (e) { - console.log(e) - return [] } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComMSSQLServer/spec/clusterAuthMode') - return val || 'x509' -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComMSSQLServer/spec/sslMode') - return val || 'requireSSL' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/clusterAuthMode') - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit( - 'wizard/model$delete', - '/resources/kubedbComMSSQLServer/spec/monitor/prometheus/exporter', - ) - } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', + params: { filter: { items: { metadata: { name: null } } } }, }, - }, - }, -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComMSSQLServer/spec/init/initialized') - watchDependency('model#/resources/kubedbComMSSQLServer/spec/init/initialized') - return !!initialized -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComMSSQLServer/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComMSSQLServer/spec/init/script') + ) - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + const resources = (resp && resp.data && resp.data.items) || [] -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/init/waitForInitialRestore', - value: false, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComMSSQLServer/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComMSSQLServer/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue( - model, - '/resources/kubedbComMSSQLServer/spec/init/script/configMap/name', - ) - const secret = getValue( - model, - '/resources/kubedbComMSSQLServer/spec/init/script/secret/secretName', - ) - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/init/script/secret') - - if ( - !valueExists(model, getValue, '/resources/kubedbComMSSQLServer/spec/init/script/configMap') - ) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComMSSQLServer/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComMSSQLServer/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( + function initMetadata() { + const dbName = + getValue( model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', + ) || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, + path: '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/name', + value: modifiedName, + force: true, }) - } - } -} -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute', ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + async function fetchTopologyMachines() { + const instance = hasAnnotations() - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } } - }) -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} - -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} - -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} - -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} + function setAllowedMachine(minmax) { + const annotations = + getValue( + model, + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/annotations', + ) || {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data - } - } catch (e) { - console.log(e) + if (minmax === 'min') return mn + else return mx } - return [] -} -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` -// FOR Backup Configuration + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) -// schedule backup + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - const coreKubestashComBackupConfiguration = getValue( - model, - '/resources/coreKubestashComBackupConfiguration', - ) - const kubeStashTarget = coreKubestashComBackupConfiguration?.spec?.target + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) - const mongoDB = getValue(model, '/resources/kubedbComMSSQLServer') - const mongoDbKind = mongoDB?.apiVersion?.split('/')?.at(0) + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - let isKubeStash = false - if ( - mongoDB?.kind === kubeStashTarget?.kind && - mongoDB?.metadata?.name === kubeStashTarget?.name && - mongoDB?.metadata?.namespace === kubeStashTarget?.namespace && - mongoDbKind === kubeStashTarget?.apiGroup - ) { - isKubeStash = true + return dependantIndex === -1 ? machines : filteredMachine } - const kubedbComMSSQLServerAnnotations = - getValue(model, '/resources/kubedbComMSSQLServer/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComMSSQLServerAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) + function hasAnnotations() { + const annotations = + getValue( + model, + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/annotations', + ) || {} + const instance = annotations['kubernetes.io/instance-type'] - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - isKubeStash, + return !!instance } -} - -function deleteKubeDbComMongDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComMSSQLServer/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubeDbComMongDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComMSSQLServer/metadata/annotations') || {} - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value + function hasNoAnnotations() { + return !hasAnnotations() } - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComMSSQLServer annotation - deleteKubeDbComMongDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] - // create stashAppscodeComBackupConfiguration and initialize it if not exists + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -async function initBackupData({ storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComMSSQLServer') - initialDbMetadata = objectCopy(dbResource.metadata) - initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check storageclass archiver annotation - if (initialArchiver) { - isArchiverAvailable = true - } else { - const storageClassName = dbResource?.spec?.storage?.storageClassName - const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` - try { - const resp = await axios.get(url) - const archAnnotation = resp.data?.metadata?.annotations - const annotationKeyToFind = `${resource}.${group}/archiver` - if (archAnnotation[annotationKeyToFind]) { - isArchiverAvailable = true - archiverObjectToCommit = { - ref: { - name: archAnnotation[annotationKeyToFind], - namespace: 'kubedb', - }, - } - } - } catch (e) { - console.log(e) - } - } - - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // set backup switch here - isBackupOn = !!config - - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends - - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` - - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions - } - - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, - } - - setDiscriminatorValue('isBackupDataLoaded', true) -} - -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} - -async function setBackupType() { - return 'BackupConfig' -} - -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - - if (dbResource?.spec?.topology && isArchiverAvailable) { - arr.push({ - description: 'Enable/Disable Archiver', - text: 'Archiver', - value: 'Archiver', - }) - } - return arr -} - -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), - force: true, - }) - } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer', - value: objectCopy(dbResource), - force: true, - }) -} - -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') - - return selectedType === type -} - -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations - - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} - -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} - -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} - -function onArchiverChange({ getValue, discriminator, commit, model, storeGet }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComMSSQLServer/spec/archiver' - if (archiverSwitch) { - commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, - }) - } else { - commit('wizard/model$delete', path) - } -} -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) - - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' - } - - commit('wizard/model$update', { - path: `/resources/kubedbComMSSQLServer/metadata/${type}`, - value: obj, - force: true, - }) -} - -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] - - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] - - commit('wizard/model$update', { - path: `/resources/kubedbComMSSQLServer/metadata/${type}`, - value: obj, - force: true, - }) -} - -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} - -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, - force: true, - }) - } -} - -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} - -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} - -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} - -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} - -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} - -function getNamespaceArray() { - return namespaceList -} - -// invoker form -function initBackupInvoker() { - return 'backupConfiguration' -} - -function initBlueprint() { - return 'create' -} -function initUsagePolicy() { - return 'Same' -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model, storeGet }) { - const kind = storeGet('/resource/layout/result/resource/kind') - const backupInvoker = getValue(discriminator, '/backupInvoker') - const annotations = getValue(model, '/resources/kubedbComMSSQLServer/metadata/annotations') - - // get name namespace labels to set in db resource when backup is not enabled initially - - if (backupInvoker === 'backupConfiguration') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: initialModel, - force: true, - }) - - if ( - !dbResource.metadata?.annotations?.['blueprint.kubestash.com/name'] && - !dbResource.metadata?.annotations?.['blueprint.kubestash.com/namespace'] - ) { - delete annotations['blueprint.kubestash.com/name'] - delete annotations['blueprint.kubestash.com/namespace'] - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/metadata/annotations', - value: annotations, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - if (!isBackupOn) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } - annotations['blueprint.kubestash.com/name'] = `${kind.toLowerCase()}-blueprint` - annotations['blueprint.kubestash.com/namespace'] = 'kubedb' - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/metadata/annotations', - value: annotations, - force: true, - }) - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComMSSQLServer/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = - getValue(model, '/resources/kubedbComMSSQLServer/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComMSSQLServer/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComMSSQLServer/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComMSSQLServer/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComMSSQLServer/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComMSSQLServer/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) - } - - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComMSSQLServer/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComMSSQLServer/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] - } -} - -//////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// - -//////////////////// service monitor /////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/mongod.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -//////////////////// custom config for sharded topology ///////////////// - -function setConfigurationSourceShard({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceShard') - if (src) return src - const value = getValue(model, '/resources/secret_shard_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function setConfigurationSourceConfigServer({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceConfigServer') - if (src) return src - const value = getValue(model, '/resources/secret_configserver_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function setConfigurationSourceMongos({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceMongos') - if (src) return src - const value = getValue(model, '/resources/secret_mongos_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function isSchemaOf(schema) { - if (schema === 'discriminator#/configurationSourceShard') { - return 'shard' - } else if (schema === 'discriminator#/configurationSourceConfigServer') { - return 'configserver' - } else { - return 'mongos' - } -} - -function disableConfigSourceOption({ - itemCtx, - discriminator, - getValue, - watchDependency, - elementUi, -}) { - watchDependency('discriminator#/configurationSourceShard') - watchDependency('discriminator#/configurationSourceConfigServer') - watchDependency('discriminator#/configurationSourceMongos') - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - if ( - itemCtx.value !== 'use-existing-config' && - itemCtx.value !== 'create-new-config' && - (configSrcShard === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcConfigServer === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcMongos === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret`) - ) { - return true - } - if ( - itemCtx.value === 'same-as-shard-config-secret' && - configSrcShard !== 'use-existing-config' && - configSrcShard !== 'create-new-config' - ) { - return true - } - if ( - itemCtx.value === 'same-as-configserver-config-secret' && - configSrcConfigServer !== 'use-existing-config' && - configSrcConfigServer !== 'create-new-config' - ) { - return true - } - if ( - itemCtx.value === 'same-as-mongos-config-secret' && - configSrcMongos !== 'use-existing-config' && - configSrcMongos !== 'create-new-config' - ) { - return true - } - return false -} - -function onConfigurationSourceMongosChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceMongos') - const configSecretName = `${getValue(model, '/metadata/release/name')}-mongos-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_mongos_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_mongos_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_mongos_config', - value: {}, - force: true, - }) - } - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/mongos/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'shard', 'mongos') - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'mongos') - } -} + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/${type}` -function onConfigurationSourceShardChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceShard') - const configSecretName = `${getValue(model, '/metadata/release/name')}-shard-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_shard_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_shard_config') - if (!value) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: '/resources/secret_shard_config', - value: {}, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: { ...annotations }, force: true, }) } - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/shard/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'shard') - } else if (configurationSource === 'same-as-mongos-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'mongos', 'shard') } -} -function onConfigurationSourceConfigServerChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceConfigServer') - const configSecretName = `${getValue(model, '/metadata/release/name')}-configserver-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_configserver_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_configserver_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_configserver_config', - value: {}, - force: true, + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name }) + return mappedList + } catch (e) { + console.log(e) } - commit('wizard/model$update', { - path: '/resources/kubedbComMSSQLServer/spec/shardTopology/configServer/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceShard') - transferConfigSecret( - { commit, model, getValue }, - 'shard', - 'configserver', - configurationSourceReference, - ) - } else if (configurationSource === 'same-as-mongos-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceMongos') - transferConfigSecret( - { commit, model, getValue }, - 'mongos', - 'configserver', - configurationSourceReference, - ) + return [] } -} -function transferConfigSecret({ commit, model, getValue }, src, des) { - const isShardedMode = getValue(model, '/resources/kubedbComMSSQLServer/spec/shardTopology') - if (isShardedMode) { - commit('wizard/model$update', { - path: `/resources/kubedbComMSSQLServer/spec/shardTopology/${ - des === 'configserver' ? 'configServer' : des - }/configSecret/name`, - value: getValue( + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( model, - `/resources/kubedbComMSSQLServer/spec/shardTopology/${ - src === 'configserver' ? 'configServer' : src - }/configSecret/name`, - ), - force: true, - }) - - commit('wizard/model$delete', `/resources/secret_${des}_config`) + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length } -} -function onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - configType, - configSrc, - discriminatorPath, -) { - if (configSrc === 'create-new-config') { - const value = getValue(discriminator, discriminatorPath) + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/${type}/controlledResources` commit('wizard/model$update', { - path: `/resources/secret_${configType}_config/stringData/mongod.conf`, - value: value, + path: path, + value: list, force: true, }) + return list } - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - if (configSrcShard === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'shard') + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' } - if (configSrcConfigServer === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'configserver') + + function setApplyToIfReady() { + return 'IfReady' } - if (configSrcMongos === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'mongos') + + function showOpsRequestOptions() { + if (isKubedb({ storeGet }) === true) return true + // watchDependency( + // 'model#/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', + // ) + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) } -} -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/mongod.conf') -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function setConfigurationShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/stringData/mongod.conf') - return value -} + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setConfigurationConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/stringData/mongod.conf') - return value -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -function setConfigurationMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/stringData/mongod.conf') - return value -} + const resources = (resp && resp.data && resp.data.items) || [] -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/mongod.conf') - return atob(value) -} + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } -function setConfigurationFilesShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/data/mongod.conf') - return atob(value) -} + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setConfigurationFilesConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/data/mongod.conf') - return atob(value) -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -function setConfigurationFilesMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/data/mongod.conf') - return atob(value) -} + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/configSecret') - commit( - 'wizard/model$delete', - '/resources/kubedbComMSSQLServer/spec/shardTopology/shard/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComMSSQLServer/spec/shardTopology/configServer/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComMSSQLServer/spec/shardTopology/mongos/configSecret', - ) - commit('wizard/model$delete', '/resources/secret_config') - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') + return ans } -} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + /****** Monitoring *********/ - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} - -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) - - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComMSSQLServer/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMSSQLServer/spec/monitor') } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/name', - value: modifiedName, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { + } + + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } + + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace', - value: namespace, + path: '/resources/kubedbComMSSQLServer/spec/monitor/prometheus/exporter', + value: {}, force: true, }) + } else { + commit( + 'wizard/model$delete', + '/resources/kubedbComMSSQLServer/spec/monitor/prometheus/exporter', + ) } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency( - 'model#/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', - ) - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue( - model, - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', - ) && !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComMSSQLServer/spec/metadata/labels') - const resources = (resp && resp.data && resp.data.items) || [] + const agent = getValue(model, '/resources/kubedbComMSSQLServer/spec/monitor/agent') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + } - const resources = (resp && resp.data && resp.data.items) || [] + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComMSSQLServer/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } - }) -} + } -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mssqlservers/${name}`, + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) } } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') - - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` + + const isKube = !!storeGet('/route/params/actions') + + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mssqlserveropsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } + + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } } - clearSpecModel({ commit }, verd) - return type === verd && spec -} -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/${autoscaleType}/cluster`, - ) + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name') || - '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from model - if (type === 'compute') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/storage', - ) - if (type === 'storage') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute', - ) -} -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', - ) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } -} - -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency( - 'model#/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', - ) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, } - updatedValue.push({ threshold, appliesUpto }) }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, - }) - } } -} -function objectCopy(obj) { - const temp = JSON.stringify(obj) - return JSON.parse(temp) -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComMSSQLServer/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mssqlserveropsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + if (!configMapName) return [] - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) + + const configMaps = (resp && resp.data && resp.data.data) || {} + + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + return configMapKeys } catch (e) { console.log(e) return [] } } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - if (minmax === 'min') return mn - else return mx -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) + const secrets = (resp && resp.data && resp.data.items) || [] - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } + } - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComMSSQLServer/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - return dependantIndex === -1 ? machines : filteredMachine -} + if (!secretName) return [] -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) - return !!instance -} + const secret = (resp && resp.data && resp.data.data) || {} -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComMSSQLServerAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] + return secretKeys + } catch (e) { + console.log(e) + return [] + } + } - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine + function returnFalse() { + return false + } - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComMSSQLServerAutoscaler/spec/compute/${type}` + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } + } + } - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value } -} -return { - getOpsRequestUrl, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - isNotShardModeSelected, - isShardModeSelected, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - getMongoDbVersions, - showAuthPasswordField, - showAuthSecretField, - showNewSecretCreateField, - isNotStandaloneMode, - showCommonStorageClassAndSizeField, - setDatabaseMode, - getStorageClassNames, - setStorageClass, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComMongDbAnnotation, - addKubeDbComMongDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfigurationSourceShard, - setConfigurationSourceConfigServer, - setConfigurationSourceMongos, - isSchemaOf, - disableConfigSourceOption, - onConfigurationSourceMongosChange, - onConfigurationSourceShardChange, - onConfigurationSourceConfigServerChange, - transferConfigSecret, - onConfigSecretModelChange, - setConfiguration, - setConfigurationShard, - setConfigurationConfigServer, - setConfigurationMongos, - setConfigurationFiles, - setConfigurationFilesShard, - setConfigurationFilesConfigServer, - setConfigurationFilesMongos, - onSetCustomConfigChange, - getCreateNameSpaceUrl, - updateConfigServerStorageClass, - - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - getNamespaceArray, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + return { + initScheduleBackup, + initScheduleBackupForEdit, + onScheduleBackupChange, + showBackupForm, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + onBackupTypeChange, + isBackupType, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showConfigList, + showSchedule, + showScheduleBackup, + getDefaultSchedule, + onInputChangeSchedule, + + isConsole, + isKubedb, + getDbDetails, + getNamespaces, + getDbs, + isRancherManaged, + onNamespaceChange, + initMetadata, + fetchTopologyMachines, + setAllowedMachine, + getMachines, + hasAnnotations, + hasNoAnnotations, + onMachineChange, + fetchNodeTopology, + isNodeTopologySelected, + setControlledResources, + setTrigger, + setApplyToIfReady, + showOpsRequestOptions, + + handleUnit, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + + setValueFromDbDetails, + } } diff --git a/charts/kubedbcom-mysql-editor-options/ui/create-ui.yaml b/charts/kubedbcom-mysql-editor-options/ui/create-ui.yaml index 8054fcfd21..c8d786d6e2 100644 --- a/charts/kubedbcom-mysql-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-mysql-editor-options/ui/create-ui.yaml @@ -1,443 +1,411 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/MySQL/versions + if: + type: function + name: isToggleOn|databases/MySQL/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/MySQL/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/MySQL/mode + loader: getAdminOptions|databases/MySQL/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/MySQL/mode + label: Database Mode + schema: schema/properties/spec/properties/mode + type: radio + - elements: + - label: Replicaset Number + schema: schema/properties/spec/properties/replicas + type: input + - label: Mode + options: + - text: Single-Primary + value: Single-Primary + - text: Multi-Primary + value: Multi-Primary + schema: schema/properties/spec/properties/groupReplication/properties/mode + type: select + if: + type: function + name: isEqualToModelPathValue|GroupReplication|/spec/mode + type: block-layout + - elements: + - label: Replicaset Number + schema: schema/properties/spec/properties/replicas + type: input + - label: Router Number + schema: schema/properties/spec/properties/innoDBCluster/properties/router/properties/replicas + type: input + - label: Mode + options: + - text: Single-Primary + value: Single-Primary + - text: Multi-Primary + value: Multi-Primary + schema: schema/properties/spec/properties/innoDBCluster/properties/mode + type: select + if: + type: function + name: isEqualToModelPathValue|InnoDBCluster|/spec/mode + type: block-layout + - elements: + - loader: getAppBindings + label: RemoteReplica SourceRef + validation: + type: required + schema: schema/properties/spec/properties/remoteReplica/properties/sourceRef + type: select + if: + type: function + name: isEqualToModelPathValue|RemoteReplica|/spec/mode + type: block-layout + - elements: + - loader: getAppBindings + label: RemoteReplica SourceRef + validation: + type: required + schema: schema/properties/spec/properties/remoteReplica/properties/sourceRef + type: select + - label: Errant Transaction Recovery Policy + options: + - text: Clone + value: Clone + - text: PseudoTransaction + value: PseudoTransaction + schema: schema/properties/spec/properties/semiSync/properties/errantTransactionRecoveryPolicy + type: select + if: + type: function + name: isEqualToModelPathValue|SemiSync|/spec/mode + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/MySQL/versions - if: isToggleOn|databases/MySQL/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/MySQL/properties/versions/properties/default + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - computed: getDefault|databases/MySQL/mode - fetch: getAdminOptions|databases/MySQL/mode - hasDescription: true - if: isToggleOn|databases/MySQL/mode - label: - text: labels.database.mode - schema: - $ref: schema#/properties/spec/properties/mode - type: radio + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - init: + type: func + value: getDefault|pointInTimeRecovery + if: + type: function + name: isToggleOn|pointInTimeRecovery + label: Point in-time Recovery? + schema: temp/recovery + type: switch - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - label: Namespace + watcher: + func: setPointInTimeRecovery + paths: + - temp/refNamespace + validation: + type: required + schema: temp/refNamespace type: input - - label: - text: Mode - options: - - text: Single-Primary - value: Single-Primary - - text: Multi-Primary - value: Multi-Primary - schema: - $ref: schema#/properties/spec/properties/groupReplication/properties/mode - type: select - if: isEqualToModelPathValue|GroupReplication|/spec/mode - type: single-step-form - - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - label: Name + watcher: + func: setPointInTimeRecovery + paths: + - temp/refDBName + validation: + type: required + schema: temp/refDBName type: input - - label: - text: labels.replicaset.router_number - schema: - $ref: schema#/properties/spec/properties/innoDBCluster/properties/router/properties/replicas + - customClass: mt-10 + label: Recovery Timestamp + schema: schema/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp type: input - - label: - text: Mode - options: - - text: Single-Primary - value: Single-Primary - - text: Multi-Primary - value: Multi-Primary - schema: - $ref: schema#/properties/spec/properties/innoDBCluster/properties/mode - type: select - if: isEqualToModelPathValue|InnoDBCluster|/spec/mode - type: single-step-form - - elements: - - fetch: getAppBindings - label: - text: RemoteReplica SourceRef - required: true - schema: - $ref: schema#/properties/spec/properties/remoteReplica/properties/sourceRef - type: select - if: isEqualToModelPathValue|RemoteReplica|/spec/mode - type: single-step-form + if: + type: function + name: showRecovery + label: Point in-time Recovery + showLabels: true + type: block-layout + - if: + type: function + name: isToggleOn|deployment + label: Deployment + options: + - description: shared + text: Shared + value: Shared + - description: Dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: ClusterTier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: NodeTopology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: - elements: - - fetch: getAppBindings - label: - text: RemoteReplica SourceRef - required: true - schema: - $ref: schema#/properties/spec/properties/remoteReplica/properties/sourceRef - type: select - - label: - text: Errant Transaction Recovery Policy + - init: + type: func + value: setMonitoring + if: + type: function + name: isToggleOn|monitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring + type: switch + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - text: Clone - value: Clone - - text: PseudoTransaction - value: PseudoTransaction - schema: - $ref: schema#/properties/spec/properties/semiSync/properties/errantTransactionRecoveryPolicy + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - if: isEqualToModelPathValue|SemiSync|/spec/mode - type: single-step-form + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default - type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size - type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - recovery: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - disable: showArchiverAlert + label: Enable Archiver? + watcher: + func: onArchiverChange + paths: + - schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default + schema: schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - computed: getDefault|pointInTimeRecovery - if: isToggleOn|pointInTimeRecovery - label: - text: Point in-time Recovery? - schema: - $ref: discriminator#/recovery + - if: + type: function + name: showArchiverAlert + label: The selected StorageClass does not support Archiver + type: warning + if: + type: function + name: showArchiver + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|tls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - discriminator: - refDBName: - type: string - refNamespace: - type: string - elements: - - label: - text: Namespace - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refNamespace - type: input - - label: - text: Name - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refDBName - type: input - - customClass: mt-10 - label: - text: Recovery Timestamp - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp - type: input - if: showRecovery - label: - text: Point in-time Recovery - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver - show_label: true - type: single-step-form - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - refresh: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - if: isToggleOn|monitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - disabled: showArchiverAlert - label: - text: Enable Archiver? - onChange: onArchiverChange - schema: - $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default - type: switch - - alertInfo: - show: true - type: neutral - if: showArchiverAlert - label: - text: The selected StorageClass does not support Archiver - type: label-element - if: showArchiver - type: single-step-form - - elements: - - if: isToggleOn|tls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - elements: - - if: isToggleOn|expose - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-mysql-editor-options/ui/functions.js b/charts/kubedbcom-mysql-editor-options/ui/functions.js index 044415e568..05d8009464 100644 --- a/charts/kubedbcom-mysql-editor-options/ui/functions.js +++ b/charts/kubedbcom-mysql-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -327,1092 +329,1109 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('recovery', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('refDBName', '') + setDiscriminatorValue('refNamespace', '') + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - const projects = resp?.data?.status?.projects - if (projects) { - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - - namespaces = projectsNamespace - } else { - namespaces = resp?.data?.status?.namespaces || [] + ) + const projects = resp?.data?.status?.projects + if (projects) { + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + + namespaces = projectsNamespace + } else { + namespaces = resp?.data?.status?.namespaces || [] + } + return namespaces + } catch (e) { + console.log(e) + return [] } - return namespaces - } catch (e) { - console.log(e) - return [] } -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function showRecovery({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/recovery') - const isRecoveryOn = getValue(discriminator, '/recovery') || '' - return isRecoveryOn -} + function showRecovery() { + // watchDependency('discriminator#/recovery') + const isRecoveryOn = getValue(discriminator, '/recovery') || '' + return isRecoveryOn + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') -function updateAlertValue({ commit, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + if (val === 'capz' && ifDedicated()) return true + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } + + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { + commit('wizard/model$update', { + path: '/spec/admin/storageClasses/default', + value: storageClass, + force: true, }) - return val - } catch (e) { - console.log(e) - return [] } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let namespaces = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, }) - url = url.slice(0, -1) } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val } catch (e) { console.log(e) - return [] } - } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -let namespaces = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!getValue(model, `/spec/admin/databases/MySQL/mode/toggle`)) { + let defMode = getDefault('databases/MySQL/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/MySQL/mode/available') || [] + if (arr.length) defMode = arr[0] + } commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/mode', + value: defMode, force: true, }) } - } catch (e) { - console.log(e) - } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/MySQL/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/MySQL/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/MySQL/mode/available') || [] - if (arr.length) defMode = arr[0] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } + namespaces = getNamespaces() + setDiscriminatorValue('/bundleApiLoaded', true) } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) - } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) + function fetchNamespaces() { + // watchDependency('discriminator#/bundleApiLoaded') + return namespaces } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + + async function getRecoveryNames(type) { + // watchDependency(`model#/spec/init/archiver/${type}/namespace`) + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` + if (type === 'encryptionSecret') + url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + const options = [] + if (namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + } + return options } - namespaces = getNamespaces({ axios, storeGet }) - setDiscriminatorValue('/bundleApiLoaded', true) -} -function fetchNamespaces({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return namespaces -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -async function getRecoveryNames({ getValue, model, watchDependency, storeGet, axios }, type) { - watchDependency(`model#/spec/init/archiver/${type}/namespace`) - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` - if (type === 'encryptionSecret') - url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - const options = [] - if (namespace) { - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, }) - } catch (e) { - console.log(e) } - } - return options -} -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + return returnArray } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` - commit('wizard/model$update', { - path: path, - value: returnArray[0], - force: true, - }) - } + let archiverMap = [] + let archiverCalled = false - return returnArray -} + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') -let archiverMap = [] -let archiverCalled = false + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName() + } -function getAdminOptions({ getValue, model, watchDependency, axios, storeGet, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + const options = getValue(model, `/spec/admin/${type}/available`) || [] - if (type === 'storageClasses' && !archiverCalled) { - getArchiverName({ axios, storeGet }) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } - const options = getValue(model, `/spec/admin/${type}/available`) || [] - - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + function showArchiver() { + return checkIfFeatureOn('archiver') } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} -function showArchiver({ getValue, model }) { - return checkIfFeatureOn({ getValue, model }, 'archiver') -} + async function getArchiverName() { + 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) -async function getArchiverName({ axios, storeGet }) { - 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) + 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') + function onArchiverChange() { + 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) - const via = getValue(model, '/spec/admin/archiver/via') + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const via = getValue(model, '/spec/admin/archiver/via') - if (!isArchiverOn) { - commit('wizard/model$update', { - path: '/spec/archiverName', - value: '', - force: true, - }) - } else { - if (via === 'VolumeSnapshotter') { + if (!isArchiverOn) { commit('wizard/model$update', { path: '/spec/archiverName', - value: found.annotation, + value: '', force: true, }) } else { - const kind = getValue(model, '/metadata/resource/kind') - commit('wizard/model$update', { - path: '/spec/archiverName', - value: kind.toLowerCase(), - force: true, - }) + if (via === 'VolumeSnapshotter') { + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) + } else { + const kind = getValue(model, '/metadata/resource/kind') + commit('wizard/model$update', { + path: '/spec/archiverName', + value: kind.toLowerCase(), + force: true, + }) + } } } -} -function showArchiverAlert({ watchDependency, model, getValue, commit }) { - watchDependency('model#/spec/admin/storageClasses/default') + function showArchiverAlert() { + // watchDependency('model#/spec/admin/storageClasses/default') - const mode = getValue(model, '/spec/mode') - if (mode === 'Standalone') return false + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false - const via = getValue(model, '/spec/admin/archiver/via') + const via = getValue(model, '/spec/admin/archiver/via') - if (via === 'VolumeSnapshotter') { - // toggle archiver to false when storageClass annotation not found - const stClass = getValue(model, '/spec/admin/storageClasses/default') - const found = archiverMap.find((item) => item.storageClass === stClass) - const show = !found?.annotation - if (show) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - return true - } else onArchiverChange({ model, getValue, commit }) - } else onArchiverChange({ model, getValue, commit }) - return false -} - -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && val + if (via === 'VolumeSnapshotter') { + // toggle archiver to false when storageClass annotation not found + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + if (show) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return true + } else onArchiverChange() + } else onArchiverChange() + return false } -} -function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} - -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const isAlertToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'alert', - ) - return isMonitorEnabled && isAlertToggleEnabled -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function returnFalse() { + return false + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') } -} -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } -function convertToLocal(input) { - const date = new Date(input) + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } - if (isNaN(date.getTime())) { - return null + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val } - return date.toString() -} + function convertToLocal(input) { + const date = new Date(input) -function getComponentLogStats(snapshot) { - if (!snapshot || !snapshot.status || !snapshot.status.components) { - return null + if (isNaN(date.getTime())) { + return null + } + + return date.toString() } - const components = snapshot.status.components - const appKind = snapshot.spec?.appRef?.kind + function getComponentLogStats(snapshot) { + if (!snapshot || !snapshot.status || !snapshot.status.components) { + return null + } + + const components = snapshot.status.components + const appKind = snapshot.spec?.appRef?.kind - if (appKind === 'MongoDB') { - for (const [key, value] of Object.entries(components)) { - if (key.endsWith('0') && value.logStats) { - return value.logStats + if (appKind === 'MongoDB') { + for (const [key, value] of Object.entries(components)) { + if (key.endsWith('0') && value.logStats) { + return value.logStats + } } } - } - if (components['log'] && components['log'].logStats) { - return components['log'].logStats + if (components['log'] && components['log'].logStats) { + return components['log'].logStats + } + + return null } - return null -} + async function setPointInTimeRecovery() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const refNamespace = getValue(discriminator, '/refNamespace') + const refDBName = getValue(discriminator, '/refDBName') -async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const refNamespace = getValue(discriminator, '/refNamespace') - const refDBName = getValue(discriminator, '/refDBName') + try { + const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` + const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` + const repositoriesResp = await axios.get(repositoriesUrl) + const snapshotsResp = await axios.get(snapshotsUrl) - try { - const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` - const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` - const repositoriesResp = await axios.get(repositoriesUrl) - const snapshotsResp = await axios.get(snapshotsUrl) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/name`, + value: repositoriesResp.data?.spec.encryptionSecret.name, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/namespace`, + value: repositoriesResp.data?.spec.encryptionSecret.namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/name`, + value: `${refDBName}-full`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/name`, + value: `${refDBName}-manifest`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/name`, - value: repositoriesResp.data?.spec.encryptionSecret.name, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/namespace`, - value: repositoriesResp.data?.spec.encryptionSecret.namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/name`, - value: `${refDBName}-full`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/name`, - value: `${refDBName}-manifest`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) + const resp = getComponentLogStats(snapshotsResp.data) - const resp = getComponentLogStats(snapshotsResp.data) + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: convertToLocal(resp?.end), + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: convertToLocal(resp?.start), + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: convertToLocal(resp?.end), + force: true, + }) + } catch (e) { + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: '', + force: true, + }) + console.log(e) + } + } - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: convertToLocal(resp?.end), - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: convertToLocal(resp?.start), - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: convertToLocal(resp?.end), - force: true, - }) - } catch (e) { - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: '', - force: true, - }) - console.log(e) + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } -} -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] - } + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -async function getAppBindings({ commit, axios, storeGet, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getAppBindings() { + const namespace = getValue(model, '/metadata/release/namespace') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { type: null }, + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { type: null }, + }, }, - }, + } + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + { + params: queryParams, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + const fileredResources = resources + .filter((item) => item.spec?.type === 'kubedb.com/mysql') + .map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: `${namespace}/${name}`, + value: { name, namespace }, + } + }) + return fileredResources + } catch (e) { + console.log(e) + return [] + } } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - { - params: queryParams, - }, - ) - const resources = (resp && resp.data && resp.data.items) || [] - - const fileredResources = resources - .filter((item) => item.spec?.type === 'kubedb.com/mysql') - .map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: `${namespace}/${name}`, - value: { name, namespace }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + setPointInTimeRecovery, + getRecoveryNames, + fetchNamespaces, + showRecovery, + showAdditionalSettings, + initBundle, + returnFalse, + isVariantAvailable, + showAuthPasswordField, + isEqualToModelPathValue, + getNamespaces, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + isMachineNotCustom, + isMachineCustom, + updateAlertValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + getNodeTopology, + filterNodeTopology, + getAdminOptions, + isToggleOn, + showAlerts, + showIssuer, + onBackupSwitch, + setMonitoring, + onAuthChange, + isConfigDatabaseOn, + clearConfiguration, + setBackup, + getDefault, + onArchiverChange, + showArchiverAlert, + showArchiver, + getAppBindings, } } - -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - setPointInTimeRecovery, - getRecoveryNames, - fetchNamespaces, - showRecovery, - showAdditionalSettings, - initBundle, - returnFalse, - isVariantAvailable, - showAuthPasswordField, - isEqualToModelPathValue, - getNamespaces, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - isMachineNotCustom, - isMachineCustom, - updateAlertValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - getNodeTopology, - filterNodeTopology, - getAdminOptions, - isToggleOn, - showAlerts, - showIssuer, - onBackupSwitch, - setMonitoring, - onAuthChange, - isConfigDatabaseOn, - clearConfiguration, - setBackup, - getDefault, - onArchiverChange, - showArchiverAlert, - showArchiver, - getAppBindings, -} diff --git a/charts/kubedbcom-mysql-editor/ui/edit-ui.yaml b/charts/kubedbcom-mysql-editor/ui/edit-ui.yaml index 8f3da50b8a..16310a5c77 100644 --- a/charts/kubedbcom-mysql-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-mysql-editor/ui/edit-ui.yaml @@ -1,1337 +1,677 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - fetch: getResources|core|v1|namespaces - label: - text: labels.namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - disableUnselect: true - disabled: true - fetch: getMySqlVersions|catalog.kubedb.com|v1alpha1|mysqlversions - label: - text: labels.database.version - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/version - type: select - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/deletionPolicy - type: radio - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/authSecret/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - elements: - - alias: reusable_alert - chart: - name: uibytebuildersdev-component-alert - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/form/properties/alert - type: reusable-element - type: single-step-form - id: alert - title: labels.alert -- form: - discriminator: - activeDatabaseMode: - default: Standalone - type: string +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - if: isNotEqualToDatabaseMode|Standalone - label: - text: labels.to_update_disabled_section - type: label-element - - customClass: mb-20 - if: isNotEqualToDatabaseMode|Standalone - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mysqlopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations - - computed: setDatabaseMode - disabled: true - hasDescription: true - label: - text: labels.database.mode - onChange: deleteDatabaseModePath + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - description: options.database.mode.Standalone.description - text: options.database.mode.Standalone.label - value: Standalone - - description: options.database.mode.GroupReplication.description - text: options.database.mode.GroupReplication.label - value: GroupReplication - - description: options.database.mode.InnoDBCluster.description - text: options.database.mode.InnoDBCluster.label - value: InnoDBCluster - schema: - $ref: discriminator#/activeDatabaseMode - type: radio - - disabled: true - if: isNotEqualToDatabaseMode|Standalone - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/replicas - type: input - - disabled: true - elements: - - fetch: getStorageClassNames - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/storage/properties/storageClassName - type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/storage/properties/resources/properties/requests/properties/storage - type: input - type: single-step-form - - disabled: true - elements: - - label: - text: labels.group_name - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/topology/properties/group/properties/name - type: input - - label: - text: labels.group_mode - options: - - text: options.groupMode.SinglePrimary - value: Single-Primary - - text: options.groupMode.MultiPrimary - value: Multi-Primary - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/topology/properties/group/properties/mode - type: radio - if: isEqualToDatabaseMode|GroupReplication - label: - text: labels.topology - show_label: true - type: single-step-form - type: single-step-form - id: topology - title: steps.1.label -- form: - discriminator: - configureTLS: - default: true - type: boolean - elements: - - label: - text: labels.to_update_tls - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mysqlopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=ReconfigureTLS - - computed: isValueExistInModel|/resources/kubedbComMySQL/spec/tls - disabled: true - label: - text: labels.enable_tls - onChange: onTlsConfigureChange - schema: - $ref: discriminator#/configureTLS - type: switch - - disabled: true + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - label: - text: labels.requireSSL_question - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/requireSSL - type: switch - - elements: - - computed: setApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - title: steps.2.label -- form: + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig + elements: + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + + - type: single-step-form + id: compute-autoscaler elements: - - disabled: disableInitializationSection - discriminator: - prePopulateDatabase: - type: string - elements: - - computed: initPrePopulateDatabase - label: - text: labels.prePopulateDatabase - onChange: onPrePopulateDatabaseChange + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getMysqlDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/prePopulateDatabase - type: radio - - discriminator: - dataSource: - type: string + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - computed: initDataSource - label: - text: labels.dataSource - onChange: onDataSourceChange - options: - - text: options.dataSource.script.text - value: script - - text: options.dataSource.stashBackup.text - value: stashBackup - schema: - $ref: discriminator#/properties/dataSource - type: select - - discriminator: - sourceVolumeType: - type: string - elements: - - label: - text: labels.script.path - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/init/properties/script/properties/scriptPath - type: input - - label: - text: labels.script.volume - type: label-element - - computed: initVolumeType - label: - text: labels.script.volumeType - onChange: onVolumeTypeChange - options: - - text: options.scriptSourceVolumeType.configMap.text - value: configMap - - text: options.scriptSourceVolumeType.secret.text - value: secret - schema: - $ref: discriminator#/properties/sourceVolumeType - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|configmaps - if: showConfigMapOrSecretName|configMap - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/init/properties/script/properties/configMap/properties/name - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|secrets - if: showConfigMapOrSecretName|secret - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/init/properties/script/properties/secret/properties/secretName - type: select - if: showScriptOrStashForm|script - type: single-step-form - - elements: - - label: - text: labels.restoreSession.snapshot - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/rules/properties/0/properties/snapshots/properties/0 - type: input - - discriminator: - repositoryChoise: - type: string + # mysql mode + - type: block-layout + label: Mysql + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql elements: - - label: - text: labels.repositories.title - type: label-element - - computed: setInitialRestoreSessionRepo - onChange: onInitRepositoryChoiseChange - options: - - text: options.createOrSelect.select.text - value: select - - text: options.createOrSelect.create.text - value: create - schema: - $ref: discriminator#/properties/repositoryChoise - type: radio - - allowUserDefinedOption: true - fetch: resourceNames|stash.appscode.com|v1alpha1|repositories - if: showRepositorySelectOrCreate|select - label: - text: labels.repositories.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/repository/properties/name - type: select - - alias: repository_create_init - chart: - name: uibytebuildersdev-component-repository-create - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRepositorySelectOrCreate|create - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRepository_init_repo/properties/spec/properties/backend - type: reusable-element - type: single-step-form - - if: returnFalse - label: - text: labels.backupConfiguration.targetReference.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/target/properties/ref/properties/name - type: input - - discriminator: - customizeRestoreJobRuntimeSettings: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMySQLAutoscaler/spec/compute/mysql/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|mysql + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/inMemoryStorage + elements: + - type: threshold-input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: threshold-input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/inMemoryStorage/properties/usageThresholdPercentage + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology elements: - - computed: initCustomizeRestoreJobRuntimeSettings - label: - isSubsection: true - text: labels.runtimeSettings.choise - onChange: onCustomizeRestoreJobRuntimeSettingsChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/customizeRestoreJobRuntimeSettings - type: radio - - alias: runtime_settings_init - chart: - name: uibytebuildersdev-component-runtime-settings - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRuntimeForm|yes - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/runtimeSettings - type: reusable-element - type: single-step-form - if: showScriptOrStashForm|stashBackup - type: single-step-form - - if: returnFalse - label: - text: labels.waitForInitialRestore - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/init/properties/waitForInitialRestore - type: switch - if: showInitializationForm - type: single-step-form - type: single-step-form - type: single-step-form - id: initialization - title: steps.3.label -- form: - discriminator: - repoInitialSelectionStatus: - type: string - scheduleBackup: - default: "yes" - type: string - elements: - - computed: initScheduleBackupForEdit - if: showScheduleBackup - label: - text: labels.backup.title - onChange: onScheduleBackupChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/scheduleBackup - type: radio - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean - elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string - elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean - elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean - elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - if: showBackupForm - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.4.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComMySQL/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean + - type: block-layout + showLabels: false elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMySQL/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: Mysql + showLabels: true elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMySQL/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMySQL/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - elements: - - elements: - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - type: single-step-form - id: pod-template - title: steps.6.label -- form: - elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.7.label -- form: - elements: - - elements: - - discriminator: - configurationSource: - default: use-existing-config - type: string - elements: - - label: - text: labels.to_update_config - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mysqlopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=Reconfigure - - disabled: true - label: - text: labels.custom_config - onChange: onConfigurationSourceChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/configurationSource - type: radio - - allowUserDefinedOption: true - disabled: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSource - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComMySQL/properties/spec/properties/configSecret/properties/name - type: select - type: single-step-form - type: single-step-form - type: single-step-form - id: custom-config - title: steps.8.label -- form: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComMySQLAutoscaler/spec/storage/mysql/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/usageThreshold + - type: input + label: Scaling Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/scalingThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComMySQL/spec/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComMySQLAutoscaler/spec/storage/mysql/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComMySQLAutoscaler/spec/storage/mysql/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: Select Namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getMysqlDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComMySQL/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComMySQLAutoscaler/spec/compute/mysql/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string - elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|mysql - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|mysql - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|mysql - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/controlledResources - type: multiselect - - elements: - - label: - text: Scaling Factor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/inMemoryStorage - show_label: true - type: single-step-form - - label: - text: containerControlledValues - options: - - RequestsAndLimits - - RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql/properties/containerControlledValues - type: select - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql - type: single-step-form - label: - text: Mysql - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/mysql - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: scaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: scaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.9.label -- form: - elements: - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: Select Namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getMysqlDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComMySQLAutoscaler/spec/storage/mysql/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/trigger - type: select - - label: - text: Expansion Mode + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComMySQL/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMySQL/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComMySQLAutoscaler/spec/storage/mysql/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComMySQLAutoscaler/spec/storage/mysql/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/upperBound - type: input - - label: - text: Scaling Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql/properties/scalingThreshold - type: input - label: - text: Mysql - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/storage/properties/mysql - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComMySQLAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.10.label -- form: - discriminator: - binding: - default: false - type: boolean + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComMySQL/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: + type: input + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComMySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: binding + label: Gateway Binding elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -type: multi-step-form + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-mysql-editor/ui/functions.js b/charts/kubedbcom-mysql-editor/ui/functions.js index 4e9488a134..f7431d90d3 100644 --- a/charts/kubedbcom-mysql-editor/ui/functions.js +++ b/charts/kubedbcom-mysql-editor/ui/functions.js @@ -1,1788 +1,1162 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + initRepositoryChoiseForEdit() -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' + } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, + function initScheduleBackup() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, ) - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + function onScheduleBackupChange() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (scheduleBackup === 'no') { + // delete stashAppscodeComBackupConfiguration + commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + // delete annotation from kubedbComMySQL annotation + deleteKubeDbComMySqlDbAnnotation(getValue, model, commit) + } else { + const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + // create stashAppscodeComBackupConfiguration and initialize it if not exists - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const dbName = getValue(model, '/metadata/release/name') - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + if ( + !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && + !isBluePrint + ) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration', + value: stashAppscodeComBackupConfiguration, + }) + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + } + } } - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false } - return ans -} + function getBackupConfigsAndAnnotations(getValue, model) { + const stashAppscodeComBackupConfiguration = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration', + ) + const kubedbComMySQLAnnotations = + getValue(model, '/resources/kubedbComMySQL/metadata/annotations') || {} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + const isBluePrint = Object.keys(kubedbComMySQLAnnotations).some( + (k) => + k === 'stash.appscode.com/backup-blueprint' || + k === 'stash.appscode.com/schedule' || + k.startsWith('params.stash.appscode.com/'), + ) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' return { - text: name, - value: name, + stashAppscodeComBackupConfiguration, + isBluePrint, } - }) -} + } -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + function deleteKubeDbComMySqlDbAnnotation(getValue, model, commit) { + const annotations = getValue(model, '/resources/kubedbComMySQL/metadata/annotations') || {} + const filteredKeyList = + Object.keys(annotations).filter( + (k) => + k !== 'stash.appscode.com/backup-blueprint' && + k !== 'stash.appscode.com/schedule' && + !k.startsWith('params.stash.appscode.com/'), + ) || [] + const filteredAnnotations = {} + filteredKeyList.forEach((k) => { + filteredAnnotations[k] = annotations[k] + }) + commit('wizard/model$update', { + path: '/resources/kubedbComMySQL/metadata/annotations', + value: filteredAnnotations, }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} -function setAddressType({ model, getValue }) { - const value = getValue(model, '/resources/kubedbComMySQL/spec/useAddressType') - - if (!value) { - return 'DNS' + // backup form + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false } - return value -} + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let namespaceList = [] + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComMySQL') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined -// ************************* Basic Info ********************************************** -async function getMySqlVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // get values.yaml to populate data when backup-config is being created + try { + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - const resources = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get(url) - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} + } catch (e) { + console.log(e) + } - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] - } -} + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } + } -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/resources/kubedbComMySQL/spec/topology') - watchDependency('model#/resources/kubedbComMySQL/spec/topology') + // check config with metadata name first + let config = configs?.find( + (item) => + item.metadata?.name === name && + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - if (modelPathValue?.mode) { - return modelPathValue.mode - } else { - return 'Standalone' - } -} + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) -let storageClassList = [] -async function getStorageClassNames({ axios, storeGet, commit, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // set backup switch here + isBackupOn = !!config - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - const resources = (resp && resp.data && resp.data.items) || [] + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` - storageClassList = resources - const initialStorageClass = getValue( - model, - '/resources/kubedbComMySQL/spec/storage/storageClassName', - ) - if (!initialStorageClass) setStorageClass({ model, getValue, commit }) - return resources -} + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions + } -function setStorageClass({ model, getValue, commit }) { - const deletionPolicy = getValue(model, '/resources/kubedbComMySQL/spec/deletionPolicy') || '' - let storageClass = - getValue(model, '/resources/kubedbComMySQL/spec/storage/storageClassName') || '' - const suffix = '-retain' + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + setDiscriminatorValue('isBackupDataLoaded', true) + } - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') + } - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function setBackupType() { + return 'BackupConfig' + } - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + function getTypes() { + const arr = [ + { + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', + }, + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] + + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) } + return arr } - if (storageClass) { + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/storage/storageClassName', - value: storageClass, + path: '/backupType', + value: type, force: true, }) - } -} - -function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - if (mode === 'GroupReplication' || mode === 'InnoDBCluster') { - replicas = getValue(model, '/resources/kubedbComMySQL/spec/replicas') - if (!replicas) { + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/replicas', - value: 3, + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), force: true, }) } + commit('wizard/model$delete', '/context') commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/topology/mode', - value: mode, - force: true, - }) - if (mode === 'GroupReplication') - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/topology/innoDBCluster') - else commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/topology/group') - } else if (mode === 'Standalone') { - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/replicas', - value: 1, + path: '/resources/kubedbComMySQL', + value: objectCopy(dbResource), force: true, }) - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/topology') } -} -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') -function isNotEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== value -} + return selectedType === type + } -// ************************** TLS ******************************88 + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations -function setApiGroup() { - return 'cert-manager.io' -} + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComMySQL/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComMySQL/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComMySQL/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComMySQL/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') + if (blueprintSwitch) addLabelAnnotation('annotations') + else deleteLabelAnnotation('annotations') + } - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver } - if (!url) return [] + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComMySQL/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) + } else { + commit('wizard/model$delete', path) + } + } - try { - const resp = await axios.get(url) + function addLabelAnnotation(type) { + const obj = objectCopy(initialDbMetadata[type]) - const resources = (resp && resp.data && resp.data.items) || [] + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` + } else { + obj['kubedb.com/archiver'] = 'true' + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$update', { + path: `/resources/kubedbComMySQL/metadata/${type}`, + value: obj, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComMySQL/spec/sslMode') - return val || 'require' -} + function deleteLabelAnnotation(type) { + const obj = initialDbMetadata[type] -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/tls', - value: { issuerRef: {}, certificates: [] }, + path: `/resources/kubedbComMySQL/metadata/${type}`, + value: obj, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/sslMode') } -} -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/monitor', - value: {}, + path: '/context', + value: context, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/monitor') + if (context === 'Create') { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, + force: true, + }) + } + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) } - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) + const list = filteredList?.map((ele) => ele.metadata.name) + return list + } -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/monitor/prometheus/exporter', - value: {}, + path: '/resources/coreKubestashComBackupConfiguration', + value: configDetails, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/monitor/prometheus/exporter') } -} -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' + } -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' + } -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName + } -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComMySQL/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComMySQL/spec/init/script') + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' + } -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) + return repoInitialSelectionStatus + } + + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, + path: modelPath, + value: session, }) } } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComMySQL/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) + /*********** Compute Autoscaling ************/ - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') + let autoscaleType = '' + let dbDetails = {} - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComMySQL/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/init/script') + function isKubedb() { + return !!storeGet('/route/params/actions') + } - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') + function isConsole() { + const isKube = isKubedb() + if (isKube) { + const dbName = storeGet('/route/params/name') || '' commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, + path: '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, }) - + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, + path: '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/name', + value: modifiedName, force: true, }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } + + return !isKube } -} -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComMySQL/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComMySQL/spec/init/script/secret/secretName') + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/init/script/secret') + const resources = (resp && resp.data && resp.data.items) || [] - if (!valueExists(model, getValue, '/resources/kubedbComMySQL/spec/init/script/configMap')) { - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/init/script/configMap') + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } - if (!valueExists(model, getValue, '/resources/kubedbComMySQL/spec/init/script/secret')) { + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + function onNamespaceChange() { + const namespace = getValue(model, '/metadata/release/namespace') + const agent = getValue(model, '/resources/kubedbComMySQL/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/init/script/secret', - value: { - secretName: '', - }, + path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + value: [namespace], + force: true, }) } } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + async function getMysqlDbs() { + // watchDependency('model#/resources/autoscalingKubedbComMySQLAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return repositoryChoise === value -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mysqls`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) + const resources = (resp && resp.data && resp.data.items) || [] - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name') || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, + path: '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/name', + value: modifiedName, force: true, }) - } - } -} -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, + // delete the other type object from vuex wizard model + if (type === 'compute') + commit('wizard/model$delete', '/resources/autoscalingKubedbComMySQLAutoscaler/spec/storage') + if (type === 'storage') + commit('wizard/model$delete', '/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute') + } + + async function fetchTopologyMachines() { + const instance = hasAnnotations() + + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) + + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration + } -// schedule bakcup + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComMySQLAnnotations = - getValue(model, '/resources/kubedbComMySQL/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComMySQLAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] - return { - stashAppscodeComBackupConfiguration, - isBluePrint, + return !!instance } -} - -function deleteKubeDbComMySqlDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComMySQL/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/metadata/annotations', - value: filteredAnnotations, - }) -} -function addKubeDbComMySqlDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComMySQL/metadata/annotations') || {} + function setAllowedMachine(minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value + if (minmax === 'min') return mn + else return mx } - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/metadata/annotations', - value: annotations, - force: true, - }) -} + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') + return dependantIndex === -1 ? machines : filteredMachine + } - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComMySQL annotation - deleteKubeDbComMySqlDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] - // create stashAppscodeComBackupConfiguration and initialize it if not exists + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine - const dbName = getValue(model, '/metadata/release/name') + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute/${type}` - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, }) commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: { ...annotations }, force: true, }) } } -} -// backup form -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} + function hasNoAnnotations() { + return !hasAnnotations() + } -async function initBackupData({ commit, storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComMySQL') - initialDbMetadata = objectCopy(dbResource.metadata) - initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check storageclass archiver annotation - if (initialArchiver) { - isArchiverAvailable = true - } else { - const storageClassName = dbResource?.spec?.storage?.storageClassName - const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, + }) + return list + } + + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` try { const resp = await axios.get(url) - const archAnnotation = resp.data?.metadata?.annotations - const annotationKeyToFind = `${resource}.${group}/archiver` - if (archAnnotation[annotationKeyToFind]) { - isArchiverAvailable = true - archiverObjectToCommit = { - ref: { - name: archAnnotation[annotationKeyToFind], - namespace: 'kubedb', - }, - } - } + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList } catch (e) { console.log(e) } + return [] } - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue(model, '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name') && + !!getValue(discriminator, '/autoscalingType') ) + } - // set backup switch here - isBackupOn = !!config + function setApplyToIfReady() { + return 'IfReady' + } - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions - } + const resources = (resp && resp.data && resp.data.items) || [] - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } } - setDiscriminatorValue('isBackupDataLoaded', true) -} + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -async function setBackupType() { - return 'BackupConfig' -} + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - - if (dbResource?.spec?.topology && isArchiverAvailable) { - arr.push({ - description: 'Enable/Disable Archiver', - text: 'Archiver', - value: 'Archiver', - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans + } + + /********** Monitoring **********/ + + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus } - return arr -} -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComMySQL/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/monitor') + } + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL', - value: objectCopy(dbResource), - force: true, - }) -} -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } - return selectedType === type -} + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComMySQL/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/monitor/prometheus/exporter') + } + } -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComMySQL/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComMySQL/spec/metadata/labels') -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} + const agent = getValue(model, '/resources/kubedbComMySQL/spec/monitor/agent') -function onArchiverChange({ getValue, discriminator, commit, model, storeGet }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComMySQL/spec/archiver' - if (archiverSwitch) { - commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, - }) - } else { - commit('wizard/model$delete', path) + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) + } } -} -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComMySQL/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } } - commit('wizard/model$update', { - path: `/resources/kubedbComMySQL/metadata/${type}`, - value: obj, - force: true, - }) -} + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] + const isKube = !!storeGet('/route/params/actions') - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mysqlopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } - commit('wizard/model$update', { - path: `/resources/kubedbComMySQL/metadata/${type}`, - value: obj, - force: true, - }) -} + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name', + ) + } + } -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } + } -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, - force: true, - }) + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } -} -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, + }) -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComMySQL/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function getNamespaceArray() { - return namespaceList -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') + if (!configMapName) return [] - return databaseName -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} + const configMaps = (resp && resp.data && resp.data.data) || {} -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} + return configMapKeys + } catch (e) { + console.log(e) + return [] + } + } -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - return repoInitialSelectionStatus -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + const secrets = (resp && resp.data && resp.data.items) || [] - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComMySQL/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComMySqlDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComMySqlDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComMySQL/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComMySQL/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComMySQL/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComMySQL/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComMySQL/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComMySQL/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComMySQL/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComMySQL/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComMySQL/spec/init/initialized') - watchDependency('model#/resources/kubedbComMySQL/spec/init/initialized') - return !!initialized -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - if (owner && cluster && namespace) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, - }, - }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) filteredSecrets.map((item) => { @@ -1794,863 +1168,201 @@ async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) return filteredSecrets } catch (e) { console.log(e) + return [] } } - return [] -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/my-config.cnf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComMySQL/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/my-config.cnf') -} + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComMySQL/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/my-config.cnf') - return atob(value) -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') + if (!secretName) return [] - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComMySQL/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - } -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/mysqlopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} + const secret = (resp && resp.data && resp.data.data) || {} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + return secretKeys + } catch (e) { + console.log(e) + return [] + } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true + function returnFalse() { + return false } -} - -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} - -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` + /********** Binding **********/ - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComMySQLBinding') + return isExposeBinding } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` - - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComMySQL/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'MySQLBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} - -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data } - } catch (e) { - console.log(e) - } - return [] -} - -function initBlueprint() { - return 'create' -} - -function initUsagePolicy() { - return 'Same' -} -function onInputChange( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} - -//////////////////// Auto Scaler ///////////////// -let autoscaleType = '' -let dbDetails = {} - -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) - - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { + if (value) { commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/namespace', - value: namespace, + path: '/resources/catalogAppscodeComMySQLBinding', + value: bindingValues, force: true, }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComMySQLBinding') } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getMysqlDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComMySQLAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mysqls`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from vuex wizard model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComMySQLAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name', - ) - } -} - -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComMySQLAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} - -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} - -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) } - if (!isNaN(threshold)) { - threshold += 'pc' + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, - }) } } -} - -function objectCopy(obj) { - const temp = JSON.stringify(obj) - return JSON.parse(temp) -} - -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComMySQLBinding') - 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 labels = getValue(model, '/resources/kubedbComMySQL/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'MySQLBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { - name: dbName, - namespace: dbNamespace, - }, - }, - } - - if (value) { - await commit('wizard/model$update', { - path: '/resources/catalogAppscodeComMySQLBinding', - value: bindingValues, - force: true, - }) - } else { - await commit('wizard/model$delete', '/resources/catalogAppscodeComMySQLBinding') - } -} -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) - - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) - - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] - } + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComMySQLAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComMySQLAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + return { + initScheduleBackup, + initScheduleBackupForEdit, + onScheduleBackupChange, + showBackupForm, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + onBackupTypeChange, + isBackupType, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showConfigList, + showSchedule, + showScheduleBackup, + getDefaultSchedule, + onInputChangeSchedule, + + isKubedb, + isConsole, + getNamespaces, + isRancherManaged, + getMysqlDbs, + initMetadata, + fetchTopologyMachines, + setTrigger, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + setControlledResources, + fetchNodeTopology, + isNodeTopologySelected, + showOpsRequestOptions, + setApplyToIfReady, + + handleUnit, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onNamespaceChange, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + + isBindingAlreadyOn, + addOrRemoveBinding, + + setValueFromDbDetails, } } - -return { - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, - handleUnit, - isConsole, - getNamespaces, - getMysqlDbs, - isKubedb, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - setAddressType, - getMySqlVersions, - setDatabaseMode, - getStorageClassNames, - deleteDatabaseModePath, - isEqualToDatabaseMode, - isNotEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComMySqlDbAnnotation, - addKubeDbComMySqlDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - disableInitializationSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - getCreateNameSpaceUrl, - setStorageClass, - - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, - getNamespaceArray, - isBindingAlreadyOn, - addOrRemoveBinding, -} diff --git a/charts/kubedbcom-oracle-editor-options/ui/create-ui.yaml b/charts/kubedbcom-oracle-editor-options/ui/create-ui.yaml index 07fcf859e7..41f3de0b58 100644 --- a/charts/kubedbcom-oracle-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-oracle-editor-options/ui/create-ui.yaml @@ -1,310 +1,302 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Oracle/versions - if: isToggleOn|databases/Oracle/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Oracle/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Oracle/versions + if: + type: function + name: isToggleOn|databases/Oracle/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Oracle/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Oracle/mode + loader: getAdminOptions|databases/Oracle/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/Oracle/mode + label: Database Mode + watcher: + func: toggleTls + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + label: Replica number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/Oracle/mode - fetch: getAdminOptions|databases/Oracle/mode - hasDescription: true - if: isToggleOn|databases/Oracle/mode - label: - text: labels.database.mode - onChange: toggleTls - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: isEqualToModelPathValue|Replicaset|/spec/mode - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine Profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage Class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Storage Size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - isHorizontal: true + if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + options: + - description: Shared + text: Shared + value: Shared + - description: Dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - init: + type: func + value: setBackup + if: + type: function + name: returnFalse + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - disable: showArchiverAlert + label: Enable Archiver? + watcher: + func: onArchiverChange + paths: + - schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default + schema: schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - if: + type: function + name: showArchiverAlert + label: The selected StorageClass does not support Archiver + type: warning + if: + type: function + name: returnFalse + type: block-layout + - elements: + - init: + type: func + value: checkHostnameOrIP + if: + type: function + name: returnFalse + label: Enable TLS? + watcher: + func: checkHostnameOrIP + paths: + - schema/properties/spec/properties/admin/properties/tls/properties/default + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - computed: setBackup - if: returnFalse - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + type: block-layout + - elements: + - init: + type: func + value: checkHostnameOrIP + if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + watcher: + func: checkHostnameOrIP + paths: + - schema/properties/spec/properties/admin/properties/expose/properties/default + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - disabled: true - elements: - - disabled: showArchiverAlert - label: - text: Enable Archiver? - onChange: onArchiverChange - schema: - $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default - type: switch - - alertInfo: - show: true - type: neutral - if: showArchiverAlert - label: - text: The selected StorageClass does not support Archiver - type: label-element - if: returnFalse - type: single-step-form - - elements: - - computed: checkHostnameOrIP - if: returnFalse - label: - text: Enable TLS? - onChange: checkHostnameOrIP - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - elements: - - computed: checkHostnameOrIP - if: isToggleOn|expose - label: - text: Expose via Gateway? - onChange: checkHostnameOrIP - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-oracle-editor-options/ui/functions.js b/charts/kubedbcom-oracle-editor-options/ui/functions.js index b89dc56ca3..c8b5b7c6f3 100644 --- a/charts/kubedbcom-oracle-editor-options/ui/functions.js +++ b/charts/kubedbcom-oracle-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1133 +317,1161 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, ) - const resources = (resp && resp.data && resp.data.items) || [] + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // // watchDependency('model#' + modelPath) + return modelPathValue === value + } + + function showAuthSecretField() { + return !showAuthPasswordField() + } -async function getMySqlVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, }, - }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + async function getMySqlVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resources = (resp && resp.data && resp.data.items) || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, + }, + } - // keep only non deprecated versions - const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - filteredMySqlVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMySqlVersions -} + const resources = (resp && resp.data && resp.data.items) || [] + + // keep only non deprecated versions + const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + filteredMySqlVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMySqlVersions } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } + } - if (owner && cluster && namespace) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // // // // watchDependency('model#/metadata/release/namespace') + + if (owner && cluster && namespace) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { + items: { + data: { username: null, password: null }, + metadata: { name: null }, + type: null, + }, }, }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) - }) + const filteredSecrets = secrets.filter((item) => { + const validType = [ + 'kubernetes.io/service-account-token', + 'Opaque', + 'kubernetes.io/basic-auth', + ] + return validType.includes(item.type) + }) - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + } } + return [] } - return [] -} -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + function updateAgentValue(val) { + commit('wizard/model$update', { + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', + force: true, + }) -function setReplicaNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 2 - } else return 1 -} -function setRouterNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 3 - } else return 1 -} + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', + force: true, + }) + } + + function setReplicaNumber() { + const modelPathValue = getValue(model, '/spec/mode') + if (modelPathValue === 'Topology') { + return 2 + } else return 1 + } + function setRouterNumber() { + const modelPathValue = getValue(model, '/spec/mode') + if (modelPathValue === 'Topology') { + return 3 + } else return 1 + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { + // // // // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const showMultiselectZone = ({ model, getValue, watchDependency }) => { + // // // // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + if (val === 'capz' && ifDedicated()) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const showSelectZone = ({ model, getValue, watchDependency }) => { + // // // // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const ifDedicated = ({ model, getValue }) => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const dedicatedOnChange = ({ model, getValue, commit }) => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const ifZones = ({ model, getValue, watchDependency }) => { + // // // // watchDependency('model#/form/capi/zones') + // // // // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const zonesOnChange = ({ model, getValue, commit }) => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getSKU() { + // // // // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} - -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses', + ) + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) + function showAlerts() { + // // // // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return ( + isMonitorEnabled && isToggleOn('alert') + ) + } - if (!getValue(model, `/spec/admin/databases/Oracle/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Oracle/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Oracle/mode/available') || [] - if (arr.length) defMode = arr[0] - } + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - if (!features.includes('tls')) { + function clearArbiterHidden() { commit('wizard/model$update', { - path: '/spec/admin/tls/default', + path: `/spec/arbiter/enabled`, value: false, force: true, }) - } - if (!features.includes('binding')) { + commit('wizard/model$update', { - path: '/spec/admin/expose/default', + path: `/spec/hidden/enabled`, value: false, force: true, }) } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) + + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } + commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - setDiscriminatorValue('/bundleApiLoaded', true) -} + if (!getValue(model, `/spec/admin/databases/Oracle/mode/toggle`)) { + let defMode = getDefault('databases/Oracle/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Oracle/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + setDiscriminatorValue('/bundleApiLoaded', true) } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` - commit('wizard/model$update', { - path: path, - value: returnArray[0], - force: true, - }) - } + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } - return returnArray -} + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + return returnArray + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + function getAdminOptions(type) { + // // // // watchDependency('discriminator#/bundleApiLoaded') - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} + const options = getValue(model, `/spec/admin/${type}/available`) || [] -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } - const backupVal = getValue(model, '/spec/backup/tool') - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) - } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + function isToggleOn(type) { + // // // // watchDependency('discriminator#/bundleApiLoaded') + // // // // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + async function getNodeTopology() { + // // // // watchDependency('model#/spec/admin/deployment/default') + // // // // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function isConfigDatabaseOn() { + // // // // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // // // // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // // // // watchDependency('model#/spec/mode') + const validType = [] + return !validType.includes(modelPathValue) + } + function showHidden() { + // // // // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // // // // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } + function showArbiter() { + // // // // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } -} -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function showIssuer() { + // // // // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers', + ) + return isTlsEnabled && isIssuerToggleEnabled + } + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) + } + + function toggleTls() { + let modelPathValue = getValue(model, '/spec/mode') commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/admin/tls/default', + value: modelPathValue !== 'Standalone', force: true, }) commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/tls/toggle', + value: modelPathValue !== 'Standalone', force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} + function showAdditionalSettings() { + // // // // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function toggleTls({ commit, model, getValue }) { - let modelPathValue = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: modelPathValue !== 'Standalone', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/admin/tls/toggle', - value: modelPathValue !== 'Standalone', - force: true, - }) -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // // // // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} - -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} - -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} - -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // // // // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // // // // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showArchiver({ watchDependency, getValue, model, commit }) { - watchDependency('model#/spec/mode') - const dbmode = getValue(model, '/spec/mode') + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // // // // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } - if (dbmode === 'Standalone') { + function onReferSecretChange() { commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, + path: '/spec/authSecret/name', + value: '', force: true, }) - return false } - return checkIfFeatureOn({ getValue, model }, 'archiver') -} -async function checkHostnameOrIP({ commit, model, getValue }) { - const tls = getValue(model, '/spec/admin/tls/default') - const expose = getValue(model, '/spec/admin/expose/default') - if (tls && expose) { - if (hostName) { + function showArchiver() { + // // // // watchDependency('model#/spec/mode') + const dbmode = getValue(model, '/spec/mode') + + if (dbmode === 'Standalone') { commit('wizard/model$update', { - path: '/spec/hostName', - value: hostName, + path: '/spec/admin/archiver/enable/default', + value: false, force: true, }) + return false + } + return checkIfFeatureOn('archiver') + } + + function checkHostnameOrIP() { + const tls = getValue(model, '/spec/admin/tls/default') + const expose = getValue(model, '/spec/admin/expose/default') + if (tls && expose) { + if (hostName) { + commit('wizard/model$update', { + path: '/spec/hostName', + value: hostName, + force: true, + }) + } else { + commit('wizard/model$update', { + path: '/spec/ip', + value: ip, + force: true, + }) + } } else { + commit('wizard/model$update', { + path: '/spec/hostName', + value: '', + force: true, + }) commit('wizard/model$update', { path: '/spec/ip', - value: ip, + value: '', force: true, }) } - } else { - commit('wizard/model$update', { - path: '/spec/hostName', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/ip', - value: '', - force: true, - }) } -} -function showArchiverAlert({ watchDependency, model, getValue, commit }) { - watchDependency('model#/spec/admin/storageClasses/default') + function onArchiverChange() { + 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) - const mode = getValue(model, '/spec/mode') - if (mode === 'Standalone') return false + if (isArchiverOn && found?.annotation) + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) + else + commit('wizard/model$update', { + path: '/spec/archiverName', + value: '', + force: true, + }) + } - const stClass = getValue(model, '/spec/admin/storageClasses/default') - const found = archiverMap.find((item) => item.storageClass === stClass) - const show = !found?.annotation + function showArchiverAlert() { + // // // // watchDependency('model#/spec/admin/storageClasses/default') - // 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, - }) - else onArchiverChange({ model, getValue, commit }) + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false - return show -} + 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, + }) + else onArchiverChange() + + return show + } + + + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + initBundle, + returnFalse, + setLimits, + setRequests, + toggleTls, + getNamespaces, + updateAlertValue, + getAdminOptions, + isToggleOn, + showAlerts, + getNodeTopology, + clearArbiterHidden, + showHidden, + isConfigDatabaseOn, + notEqualToDatabaseMode, + filterNodeTopology, + onAuthChange, + setMonitoring, + isMachineNotCustom, + isMachineCustom, + showIssuer, + showArbiter, + clearConfiguration, + showStorageSizeField, + onBackupSwitch, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + showAuthSecretField, + getResources, + getMySqlVersions, + onCreateAuthSecretChange, + getSecrets, + getMachineListForOptions, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + setReplicaNumber, + setRouterNumber, + setBackup, + showAdditionalSettings, + getDefault, + showArchiver, + checkHostnameOrIP, + onArchiverChange, + showArchiverAlert, + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - setLimits, - setRequests, - toggleTls, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - showStorageSizeField, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - getResources, - getMySqlVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - setReplicaNumber, - setRouterNumber, - setBackup, - showAdditionalSettings, - getDefault, - showArchiver, - checkHostnameOrIP, - showArchiverAlert, } diff --git a/charts/kubedbcom-perconaxtradb-editor-options/ui/create-ui.yaml b/charts/kubedbcom-perconaxtradb-editor-options/ui/create-ui.yaml index 056666cbab..d18bc3bc8c 100644 --- a/charts/kubedbcom-perconaxtradb-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-perconaxtradb-editor-options/ui/create-ui.yaml @@ -1,294 +1,263 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/PerconaXtraDB/versions - if: isToggleOn|databases/PerconaXtraDB/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/PerconaXtraDB/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/PerconaXtraDB/versions + if: + type: function + name: isToggleOn|databases/PerconaXtraDB/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/PerconaXtraDB/properties/versions/properties/default + type: select + - label: Replicaset Number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory type: input + label: Machine profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage select + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Storage size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment + options: + - description: shared + text: Shared + value: Shared + - description: Dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: ClusterTier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: labels.placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: NodeTopology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default type: select + hideBlock: true + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size - type: input - type: single-step-form - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|tls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default + type: switch + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - elements: - - if: isToggleOn|tls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-perconaxtradb-editor-options/ui/functions.js b/charts/kubedbcom-perconaxtradb-editor-options/ui/functions.js index 3c13475433..788724d4c3 100644 --- a/charts/kubedbcom-perconaxtradb-editor-options/ui/functions.js +++ b/charts/kubedbcom-perconaxtradb-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -304,1053 +306,1048 @@ const machineList = [ 'db.r.24xlarge', ] -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + function showMonitoringSection() { + // watchDependency('discriminator#/monitoringEnabledStatus') + return !!getValue(discriminator, '/monitoringEnabledStatus') + } + + function setMonitoringStatus() { + const status = getValue(model, '/spec/monitoring/agent') + return !!status + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') -function showMonitoringSection({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/monitoringEnabledStatus') - return !!getValue(discriminator, '/monitoringEnabledStatus') -} + if (val === 'capz' && ifDedicated()) return true + } -function setMonitoringStatus({ model, getValue }) { - const status = getValue(model, '/spec/monitoring/agent') - return !!status -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') - } -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { + commit('wizard/model$update', { + path: '/spec/admin/storageClasses/default', + value: storageClass, + force: true, }) - return val - } catch (e) { - console.log(e) - return [] } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, }) - url = url.slice(0, -1) } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val } catch (e) { console.log(e) - return [] } - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] - -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!getValue(model, `/spec/admin/databases/PerconaXtraDB/mode/toggle`)) { + let defMode = getDefault('databases/PerconaXtraDB/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/PerconaXtraDB/mode/available') || [] + if (arr.length) defMode = arr[0] + } commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/mode', + value: defMode, force: true, }) } - } catch (e) { - console.log(e) - } - - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - if (!getValue(model, `/spec/admin/databases/PerconaXtraDB/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/PerconaXtraDB/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/PerconaXtraDB/mode/available') || [] - if (arr.length) defMode = arr[0] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) - } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) + setDiscriminatorValue('/bundleApiLoaded', true) } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) - } - - setDiscriminatorValue('/bundleApiLoaded', true) -} -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` - commit('wizard/model$update', { - path: path, - value: returnArray[0], - force: true, - }) + return returnArray } - return returnArray -} + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (options.length === 0) { + return fetchOptions(type) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + return options } - return options -} - -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } } - const backupVal = getValue(model, '/spec/backup/tool') - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) - } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const isAlertToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'alert', - ) - return isMonitorEnabled && isAlertToggleEnabled -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } -} -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + function clearArbiterHidden() { + commit('wizard/model$update', { + path: `/spec/arbiter/enabled`, + value: false, + force: true, + }) -function returnFalse() { - return false -} + commit('wizard/model$update', { + path: `/spec/hidden/enabled`, + value: false, + force: true, + }) + } -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } } -} -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} + function showAuthSecretField() { + return !showAuthPasswordField() + } -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = [] + return !validType.includes(modelPathValue) + } -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getPerconaXtraDBVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, }, - }, - } - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + } - const resources = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const resources = (resp && resp.data && resp.data.items) || [] - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions -} + // keep only non deprecated versions + const filteredVersions = resources.filter((item) => item.spec && !item.spec.deprecated) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + filteredVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredVersions } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } + } - const secrets = (resp && resp.data && resp.data.items) || [] + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + const secrets = (resp && resp.data && resp.data.items) || [] -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function showReplicaField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Replicaset'] - return validType.includes(modelPathValue) -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function onModeChange({ model, getValue, watchDependency, commit }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - if (modelPathValue === 'Replicaset') { + function updateAgentValue(val) { commit('wizard/model$update', { - path: '/spec/replicas', - value: 3, + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', force: true, }) - } else { + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/spec/replicas', - value: 1, + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', force: true, }) } -} -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function showReplicaField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Replicaset'] + return validType.includes(modelPathValue) + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function onModeChange() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + if (modelPathValue === 'Replicaset') { + commit('wizard/model$update', { + path: '/spec/replicas', + value: 3, + force: true, + }) + } else { + commit('wizard/model$update', { + path: '/spec/replicas', + value: 1, + force: true, + }) + } + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - showAdditionalSettings, - initBundle, - returnFalse, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - returnFalse, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - showStorageSizeField, - getResources, - getMongoDbVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - showReplicaField, - onModeChange, - setBackup, - getDefault, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + showAdditionalSettings, + initBundle, + returnFalse, + getNamespaces, + updateAlertValue, + getAdminOptions, + isToggleOn, + showAlerts, + getNodeTopology, + clearArbiterHidden, + showHidden, + isConfigDatabaseOn, + notEqualToDatabaseMode, + filterNodeTopology, + onAuthChange, + setMonitoring, + isMachineNotCustom, + isMachineCustom, + showIssuer, + showArbiter, + clearConfiguration, + onBackupSwitch, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + showAuthSecretField, + showStorageSizeField, + getResources, + getPerconaXtraDBVersions, + onCreateAuthSecretChange, + getSecrets, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + showReplicaField, + onModeChange, + setBackup, + getDefault, + } } diff --git a/charts/kubedbcom-perconaxtradb-editor/ui/edit-ui.yaml b/charts/kubedbcom-perconaxtradb-editor/ui/edit-ui.yaml index 3fb2c605c1..c92b77506b 100644 --- a/charts/kubedbcom-perconaxtradb-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-perconaxtradb-editor/ui/edit-ui.yaml @@ -1,637 +1,516 @@ -steps: -- form: +type: multi-step-form +step: + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType + options: + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines + elements: + # perconaxtradb mode + - type: block-layout + label: PerconaXtraDB + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/perconaxtradb/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|perconaxtradb + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|perconaxtradb + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: machine-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/maxAllowed/properties/cpu + - type: machine-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|perconaxtradb + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: block-layout + showLabels: false elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/perconaxtradb/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string + - type: block-layout + showLabels: false elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|perconaxtradb - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|perconaxtradb - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|perconaxtradb - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb/properties/controlledResources - type: multiselect - label: - text: PerconaXtraDB - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: block-layout + label: PerconaXtraDB + showLabels: true + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComPerconaXtraDBAutoscaler/spec/storage/perconaxtradb/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComPerconaXtraDB/spec/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComPerconaXtraDBAutoscaler/spec/storage/perconaxtradb/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComPerconaXtraDBAutoscaler/spec/storage/perconaxtradb/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - computed: getDbDetails - if: returnFalse - type: input - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComPerconaXtraDBAutoscaler/spec/storage/perconaxtradb/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/trigger - type: select - - label: - text: Expansion Mode + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComPerconaXtraDB/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection + elements: + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComPerconaXtraDB/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPerconaXtraDB/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComPerconaXtraDBAutoscaler/spec/storage/perconaxtradb/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComPerconaXtraDBAutoscaler/spec/storage/perconaxtradb/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/storage/properties/perconaxtradb/properties/upperBound - type: input - label: - text: PerconaXtraDB - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/compute/properties/perconaxtradb - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPerconaXtraDBAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.7.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComPerconaXtraDB/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComPerconaXtraDB/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPerconaXtraDB/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPerconaXtraDB/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPerconaXtraDB/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -type: multi-step-form + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComPerconaXtraDB/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true diff --git a/charts/kubedbcom-perconaxtradb-editor/ui/functions.js b/charts/kubedbcom-perconaxtradb-editor/ui/functions.js index cb31d41c9a..fb1f23191f 100644 --- a/charts/kubedbcom-perconaxtradb-editor/ui/functions.js +++ b/charts/kubedbcom-perconaxtradb-editor/ui/functions.js @@ -1,3109 +1,885 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} + /********** Initialize Discriminator **************/ -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + let autoscaleType = '' + let dbDetails = {} - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + function isConsole() { + const isKube = isKubedb() - const resources = (resp && resp.data && resp.data.items) || [] + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + return !isKube } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -function isNotShardModeSelected({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComPerconaXtraDB/spec') - const hasShardTopology = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/shardTopology') - return !hasShardTopology -} -function isShardModeSelected({ model, getValue, watchDependency, commit }) { - const resp = !isNotShardModeSelected({ model, getValue, watchDependency }) - if (resp) { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') + function isKubedb() { + return !!storeGet('/route/params/actions') } - return resp -} -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace', + ) || + '' + const name = + storeGet('/route/params/name') || + getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', + ) || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/perconaxtradbs/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) } - return ans -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + const resources = (resp && resp.data && resp.data.items) || [] -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -// ************************* Basic Info ********************************************** -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', + ) + } } - try { + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredMongoDbVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true + return { + text: name, + value: name, + } }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] } -} - -// ************************* Auth Secret Field ****************************************** -function showAuthPasswordField({ model, getValue, watchDependency }) { - watchDependency('model#/resources') - const modelPathValue = getValue(model, '/resources') - return !!( - modelPathValue && - modelPathValue.secret && - modelPathValue.secret.metadata && - modelPathValue.secret.metadata.name && - !showAuthSecretField({ model, getValue, watchDependency }) - ) -} -function showAuthSecretField({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComPerconaXtraDB/spec') - const modelPathValue = getValue(model, '/resources/kubedbComPerconaXtraDB/spec') - return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) -} + function initMetadata() { + const dbName = + getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', + ) || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) -function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { - const resp = - !showAuthSecretField({ model, getValue, watchDependency }) && - !showAuthPasswordField({ model, getValue, watchDependency }) - const secret = getValue(model, '/resources/secret_auth') - if (resp && !secret) { - commit('wizard/model$update', { - path: '/resources/secret_auth', - value: { - data: { - password: '', - }, - }, - force: true, - }) + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute', + ) } - return resp -} -// ********************* Database Mode *********************** -function isNotStandaloneMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Standalone' -} + async function fetchTopologyMachines() { + const instance = hasAnnotations() -function showCommonStorageClassAndSizeField({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(mode) -} -function setDatabaseMode({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/resources/kubedbComPerconaXtraDB/spec') - - watchDependency('model#/resources/kubedbComPerconaXtraDB/spec') - if (modelPathValue.shardTopology) { - return 'Sharded' - } else if (modelPathValue.replicaSet) { - return 'Replicaset' - } else { - return 'Standalone' + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) + + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } -} -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, model, getValue, watchDependency, discriminator }, - mode, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const databaseModeShard = getValue(discriminator, '/activeDatabaseMode') === 'Sharded' - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - storageClassList = resources - const path = - mode === 'shard' - ? '/resources/kubedbComPerconaXtraDB/spec/shardTopology/shard/storage/storageClassName' - : '/resources/kubedbComPerconaXtraDB/spec/storage/storageClassName' - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ getValue, commit, model, discriminator }) - return resources -} + function setApplyToIfReady() { + return 'IfReady' + } -function setStorageClass({ getValue, commit, model, discriminator }) { - const deletionPolicy = - getValue(model, 'resources/kubedbComPerconaXtraDB/spec/deletionPolicy') || '' - const suffix = '-retain' - let storageClass = '' + function hasAnnotations() { + const annotations = + getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/annotations', + ) || {} + const instance = annotations['kubernetes.io/instance-type'] - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + return !!instance + } - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + function hasNoAnnotations() { + return !hasAnnotations() + } - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function setAllowedMachine(minmax) { + const annotations = + getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/annotations', + ) || {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } + if (minmax === 'min') return mn + else return mx } - const mode = getValue(discriminator, '/activeDatabaseMode') + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` - if (mode === 'Sharded') { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/shard/storage/storageClassName', - value: storageClass, - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, - force: true, - }) - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/storage') - } else { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/storage/storageClassName', - value: storageClass, - force: true, + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) + + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } }) + + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) + + return dependantIndex === -1 ? machines : filteredMachine } -} -function updateConfigServerStorageClass({ getValue, model, commit }) { - const storageClass = - getValue( - model, - '/resources/kubedbComPerconaXtraDB/spec/shardTopology/shard/storage/storageClassName', - ) || '' - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, - force: true, - }) -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] -function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - const modelSpec = getValue(model, '/resources/kubedbComPerconaXtraDB/spec') - if (mode === 'Sharded') { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/podTemplate') - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/configSecret') + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine - commit('wizard/model$delete', '/resources/secret_config') + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/${type}` - if (!modelSpec.shardTopology) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology', - value: { - configServer: { - replicas: 3, - storage: { - resources: { - requests: { - storage: '', - }, - }, - }, - }, - mongos: { - replicas: 2, - }, - shard: { - replicas: 3, - shards: 3, - storage: { - resources: { - requests: { - storage: '', - }, - }, - }, - }, - }, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, force: true, }) - } - } else if (mode === 'Replicaset') { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/shardTopology') - - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') - - if (!modelSpec.replicaSet) { commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/replicaSet', - value: { name: '' }, + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, force: true, }) commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/replicas', - value: 3, + path: annoPath, + value: annotations, force: true, }) } - } else if (mode === 'Standalone') { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/shardTopology') - - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/replicas') + } - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, + }) + return list + } + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] } -} -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } -// ************************** TLS ******************************88 + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency( + // 'model#/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', + // ) + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) + } -function setApiGroup() { - return 'cert-manager.io' -} + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } + } + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComPerconaXtraDB/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComPerconaXtraDB/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value } - if (!url) return [] + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { - const resp = await axios.get(url) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ + async function getNamespacedResourceList( axios, storeGet, - getValue, - model, - watchDependency, - }) + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return !!(resp && resp.length) -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - return !resp -} + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/clusterAuthMode') - return val || 'x509' -} + return ans + } -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/sslMode') - return val || 'requireSSL' -} + /****** Monitoring *********/ -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComPerconaXtraDB/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/monitor') + } + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/tls', - value: { issuerRef: {}, certificates: [] }, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/clusterAuthMode') - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/sslMode') } -} -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComPerconaXtraDB/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit( + 'wizard/model$delete', + '/resources/kubedbComPerconaXtraDB/spec/monitor/prometheus/exporter', + ) + } + } -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/monitor') + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue } - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/metadata/labels') -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit( - 'wizard/model$delete', - '/resources/kubedbComPerconaXtraDB/spec/monitor/prometheus/exporter', - ) - } -} + const agent = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/monitor/agent') -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/init/initialized') - watchDependency('model#/resources/kubedbComPerconaXtraDB/spec/init/initialized') - return !!initialized -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComPerconaXtraDB/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/init/script') - - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} - -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComPerconaXtraDB/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue( - model, - '/resources/kubedbComPerconaXtraDB/spec/init/script/configMap/name', - ) - const secret = getValue( - model, - '/resources/kubedbComPerconaXtraDB/spec/init/script/secret/secretName', - ) - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/init/script/secret') - - if ( - !valueExists(model, getValue, '/resources/kubedbComPerconaXtraDB/spec/init/script/configMap') - ) { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/init/script/configMap') - - if ( - !valueExists(model, getValue, '/resources/kubedbComPerconaXtraDB/spec/init/script/secret') - ) { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} - -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) - } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} - -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} - -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} - -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) - } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` - - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} - -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - data = data.map((ele) => ele.metadata.name) - return data - } - } catch (e) { - console.log(e) - } - return [] -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule backup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - - const coreKubestashComBackupConfiguration = getValue( - model, - '/resources/coreKubestashComBackupConfiguration', - ) - const kubeStashTarget = coreKubestashComBackupConfiguration?.spec?.target - - const mongoDB = getValue(model, '/resources/kubedbComPerconaXtraDB') - const mongoDbKind = mongoDB?.apiVersion?.split('/')?.at(0) - - let isKubeStash = false - if ( - mongoDB?.kind === kubeStashTarget.kind && - mongoDB?.metadata?.name === kubeStashTarget?.name && - mongoDB?.metadata?.namespace === kubeStashTarget?.namespace && - mongoDbKind === kubeStashTarget?.apiGroup - ) { - isKubeStash = true - } - - const kubedbComPerconaXtraDBAnnotations = - getValue(model, '/resources/kubedbComPerconaXtraDB/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComPerconaXtraDBAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - isKubeStash, - } -} - -function deleteKubeDbComMongDbAnnotation(getValue, model, commit) { - const annotations = - getValue(model, '/resources/kubedbComPerconaXtraDB/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubeDbComMongDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = - getValue(model, '/resources/kubedbComPerconaXtraDB/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComPerconaXtraDB annotation - deleteKubeDbComMongDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -// invoker form -async function initBackupInvoker({ getValue, model, storeGet, commit, axios }) { - const { stashAppscodeComBackupConfiguration, isBluePrint, isKubeStash } = - getBackupConfigsAndAnnotations(getValue, model) - - const apiGroup = getValue(model, '/metadata/resource/group') - let kind = getValue(model, '/metadata/resource/kind') - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const name = storeGet('/route/params/name') - const namespace = storeGet('/route/query/namespace') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - let labels = {} - - const sessions = getValue(model, '/resources/coreKubestashComBackupConfiguration/spec/sessions') - sessions[0].repositories[0].name = name - sessions[0].repositories[0].directory = `/${name}` - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/spec/sessions', - value: sessions, - force: true, - }) - - const url = `clusters/${username}/${clusterName}/proxy/${group}/${version}/namespaces/${namespace}/${resource}/${name}` - - try { - const resp = await axios.get(url) - labels = resp.data.metadata.labels - kind = resp.data.kind - } catch (e) { - console.log(e) - } - - commit('wizard/model$update', { - path: '/metadata/release', - value: { - labels: labels, - name: name, - namespace: namespace, - }, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/metadata', - value: { - labels: labels, - name: name, - namespace: namespace, - }, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/spec/target', - value: { - apiGroup: apiGroup, - kind: kind, - name: name, - namespace: namespace, - }, - force: true, - }) - - let isStashPresetEnable = false - try { - const url = `/clusters/${username}/${clusterName}/proxy/ui.k8s.appscode.com/v1alpha1/features` - const resp = await axios.get(url) - const stashFeature = resp.data.items.filter((item) => { - return item.metadata.name === 'stash-presets' - }) - if (stashFeature[0].status?.enabled) { - isStashPresetEnable = true - } - } catch (e) { - console.log(e) - } - let schedule = '' - let storageRefName = '' - let storageRefNamespace = '' - let retentionPolicyName = '' - let retentionPolicyNamespace = '' - let encryptionSecretName = '' - let encryptionSecretNamespace = '' - - if (isStashPresetEnable) { - try { - const url = `clusters/${username}/${clusterName}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/stash-presets` - const resp = await axios.get(url) - schedule = resp.data.spec.values.spec.backup.kubestash.schedule - storageRefName = resp.data.spec.values.spec.backup.kubestash.storageRef.name - storageRefNamespace = resp.data.spec.values.spec.backup.kubestash.storageRef.namespace - retentionPolicyName = resp.data.spec.values.spec.backup.kubestash.retentionPolicy.name - retentionPolicyNamespace = - resp.data.spec.values.spec.backup.kubestash.retentionPolicy.namespace - encryptionSecretName = resp.data.spec.values.spec.backup.kubestash.encryptionSecret.name - encryptionSecretNamespace = - resp.data.spec.values.spec.backup.kubestash.encryptionSecret.namespace - } catch (e) { - console.log(e) - } - } - setInitSchedule( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions/', - schedule, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'storageRef', - 'namespace', - storageRefNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'storageRef', - 'name', - storageRefName, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'retentionPolicy', - 'namespace', - retentionPolicyNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'retentionPolicy', - 'name', - retentionPolicyName, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions', - 'encryptionSecret', - 'namespace', - encryptionSecretNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions', - 'encryptionSecret', - 'name', - encryptionSecretName, - ) - - if (isKubeStash) return 'backupConfiguration' - else if (stashAppscodeComBackupConfiguration) return 'legacyBackupConfiguration' - else if (isBluePrint) return 'backupBlueprint' - else return 'backupConfiguration' -} - -function initBlueprint() { - return 'create' -} -function initUsagePolicy() { - return 'Same' -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model }) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - - if (backupInvoker === 'backupConfiguration') { - // delete annotation and create backup config object - deleteKubeDbComMongDbAnnotation(getValue, model, commit) - const dbName = getValue(model, '/metadata/release/name') - - if (!valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - // delete backup configuration object and create the annotation - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - addKubeDbComMongDbAnnotation(getValue, model, commit, 'stash.appscode.com/backup-blueprint', '') - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - discriminatorName, -) { - watchDependency(`model#/${modelPath}`) - const session = getValue(model, modelPath) - return session[0].scheduler.schedule -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComPerconaXtraDB/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = - getValue(model, '/resources/kubedbComPerconaXtraDB/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) - } - - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] - } -} - -//////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// - -//////////////////// service monitor /////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/mongod.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -//////////////////// custom config for sharded topology ///////////////// - -function setConfigurationSourceShard({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceShard') - if (src) return src - const value = getValue(model, '/resources/secret_shard_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function setConfigurationSourceConfigServer({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceConfigServer') - if (src) return src - const value = getValue(model, '/resources/secret_configserver_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function setConfigurationSourceMongos({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceMongos') - if (src) return src - const value = getValue(model, '/resources/secret_mongos_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function isSchemaOf(schema) { - if (schema === 'discriminator#/configurationSourceShard') { - return 'shard' - } else if (schema === 'discriminator#/configurationSourceConfigServer') { - return 'configserver' - } else { - return 'mongos' - } -} - -function disableConfigSourceOption({ - itemCtx, - discriminator, - getValue, - watchDependency, - elementUi, -}) { - watchDependency('discriminator#/configurationSourceShard') - watchDependency('discriminator#/configurationSourceConfigServer') - watchDependency('discriminator#/configurationSourceMongos') - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - if ( - itemCtx.value !== 'use-existing-config' && - itemCtx.value !== 'create-new-config' && - (configSrcShard === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcConfigServer === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcMongos === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret`) - ) { - return true - } - if ( - itemCtx.value === 'same-as-shard-config-secret' && - configSrcShard !== 'use-existing-config' && - configSrcShard !== 'create-new-config' - ) { - return true - } - if ( - itemCtx.value === 'same-as-configserver-config-secret' && - configSrcConfigServer !== 'use-existing-config' && - configSrcConfigServer !== 'create-new-config' - ) { - return true - } - if ( - itemCtx.value === 'same-as-mongos-config-secret' && - configSrcMongos !== 'use-existing-config' && - configSrcMongos !== 'create-new-config' - ) { - return true - } - return false -} - -function onConfigurationSourceMongosChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceMongos') - const configSecretName = `${getValue(model, '/metadata/release/name')}-mongos-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_mongos_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_mongos_config') - if (!value) { + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/secret_mongos_config', - value: {}, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, force: true, }) } - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/mongos/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'shard', 'mongos') - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'mongos') } -} -function onConfigurationSourceShardChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceShard') - const configSecretName = `${getValue(model, '/metadata/release/name')}-shard-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_shard_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_shard_config') - if (!value) { + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/secret_shard_config', - value: {}, + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], force: true, }) + + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/shard/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'shard') - } else if (configurationSource === 'same-as-mongos-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'mongos', 'shard') } -} -function onConfigurationSourceConfigServerChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceConfigServer') - const configSecretName = `${getValue(model, '/metadata/release/name')}-configserver-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_configserver_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace', ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_configserver_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_configserver_config', - value: {}, - force: true, - }) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', + ) } - commit('wizard/model$update', { - path: '/resources/kubedbComPerconaXtraDB/spec/shardTopology/configServer/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceShard') - transferConfigSecret( - { commit, model, getValue }, - 'shard', - 'configserver', - configurationSourceReference, - ) - } else if (configurationSource === 'same-as-mongos-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceMongos') - transferConfigSecret( - { commit, model, getValue }, - 'mongos', - 'configserver', - configurationSourceReference, - ) - } -} - -function transferConfigSecret({ commit, model, getValue }, src, des) { - const isShardedMode = getValue(model, '/resources/kubedbComPerconaXtraDB/spec/shardTopology') - if (isShardedMode) { - commit('wizard/model$update', { - path: `/resources/kubedbComPerconaXtraDB/spec/shardTopology/${ - des === 'configserver' ? 'configServer' : des - }/configSecret/name`, - value: getValue( - model, - `/resources/kubedbComPerconaXtraDB/spec/shardTopology/${ - src === 'configserver' ? 'configServer' : src - }/configSecret/name`, - ), - force: true, - }) - - commit('wizard/model$delete', `/resources/secret_${des}_config`) - } -} - -function onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - configType, - configSrc, - discriminatorPath, -) { - if (configSrc === 'create-new-config') { - const value = getValue(discriminator, discriminatorPath) - commit('wizard/model$update', { - path: `/resources/secret_${configType}_config/stringData/mongod.conf`, - value: value, - force: true, - }) - } - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - - if (configSrcShard === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'shard') } - if (configSrcConfigServer === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'configserver') - } - if (configSrcMongos === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'mongos') - } -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/mongod.conf') -} - -function setConfigurationShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/stringData/mongod.conf') - return value -} - -function setConfigurationConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/stringData/mongod.conf') - return value -} - -function setConfigurationMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/stringData/mongod.conf') - return value -} - -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/mongod.conf') - return atob(value) -} - -function setConfigurationFilesShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/data/mongod.conf') - return atob(value) -} - -function setConfigurationFilesConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/data/mongod.conf') - return atob(value) -} - -function setConfigurationFilesMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/data/mongod.conf') - return atob(value) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComPerconaXtraDB/spec/configSecret') - commit( - 'wizard/model$delete', - '/resources/kubedbComPerconaXtraDB/spec/shardTopology/shard/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComPerconaXtraDB/spec/shardTopology/configServer/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComPerconaXtraDB/spec/shardTopology/mongos/configSecret', - ) - commit('wizard/model$delete', '/resources/secret_config') - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') - } -} + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const isKube = !!storeGet('/route/params/actions') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/perconaxtradbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} - -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} - -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) - - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace', - value: namespace, - force: true, + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } + } + + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } + } + + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } + + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, + }) + + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) } - } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency( - 'model#/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', - ) - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue( + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', - ) && !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + '/resources/kubedbComPerconaXtraDB/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) - const resources = (resp && resp.data && resp.data.items) || [] + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + if (!configMapName) return [] -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + const configMaps = (resp && resp.data && resp.data.data) || {} - const resources = (resp && resp.data && resp.data.items) || [] + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + return configMapKeys + } catch (e) { + console.log(e) + return [] } - }) -} + } -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue( - model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', - ) || - '' + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/perconaxtradbs/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) - } - } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') + const secrets = (resp && resp.data && resp.data.items) || [] - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' - } - clearSpecModel({ commit }, verd) - return type === verd && spec -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/${autoscaleType}/cluster`, - ) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } } -} -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue( + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', - ) || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from model - if (type === 'compute') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/storage', - ) - if (type === 'storage') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute', - ) -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', + '/resources/kubedbComPerconaXtraDB/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', ) - } -} - -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency( - 'model#/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', - ) - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} - -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} - -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, - }) - } - } -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -function setMetadata({ storeGet, mode, commit }) { - const dbname = storeGet('/route/params/name') || '' - const namespace = storeGet('/route/query/namespace') || '' - if (mode === 'standalone-step') { - commit('wizard/model$update', { - path: '/metadata/release/name', - value: dbname, - force: true, - }) - commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, - force: true, - }) - } -} + if (!secretName) return [] -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/perconaxtradbopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + const secret = (resp && resp.data && resp.data.data) || {} - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + return secretKeys } catch (e) { console.log(e) return [] } } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComPerconaXtraDBAutoscaler/spec/compute/${type}` + function returnFalse() { + return false + } - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value } -} -return { - getOpsRequestUrl, - setMetadata, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - isNotShardModeSelected, - isShardModeSelected, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - getMongoDbVersions, - showAuthPasswordField, - showAuthSecretField, - showNewSecretCreateField, - isNotStandaloneMode, - showCommonStorageClassAndSizeField, - setDatabaseMode, - getStorageClassNames, - setStorageClass, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComMongDbAnnotation, - addKubeDbComMongDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfigurationSourceShard, - setConfigurationSourceConfigServer, - setConfigurationSourceMongos, - isSchemaOf, - disableConfigSourceOption, - onConfigurationSourceMongosChange, - onConfigurationSourceShardChange, - onConfigurationSourceConfigServerChange, - transferConfigSecret, - onConfigSecretModelChange, - setConfiguration, - setConfigurationShard, - setConfigurationConfigServer, - setConfigurationMongos, - setConfigurationFiles, - setConfigurationFilesShard, - setConfigurationFilesConfigServer, - setConfigurationFilesMongos, - onSetCustomConfigChange, - getCreateNameSpaceUrl, - updateConfigServerStorageClass, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + return { + isConsole, + isKubedb, + getDbDetails, + getNamespaces, + isRancherManaged, + onNamespaceChange, + getDbs, + initMetadata, + fetchTopologyMachines, + setTrigger, + setApplyToIfReady, + hasAnnotations, + hasNoAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + setControlledResources, + fetchNodeTopology, + isNodeTopologySelected, + showOpsRequestOptions, + handleUnit, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + + setValueFromDbDetails, + } } diff --git a/charts/kubedbcom-pgbouncer-editor-options/ui/create-ui.yaml b/charts/kubedbcom-pgbouncer-editor-options/ui/create-ui.yaml index 238304dcce..6902ba972a 100644 --- a/charts/kubedbcom-pgbouncer-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-pgbouncer-editor-options/ui/create-ui.yaml @@ -1,308 +1,280 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/PgBouncer/versions - if: isToggleOn|databases/PgBouncer/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/PgBouncer/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/PgBouncer/versions + if: + type: function + name: isToggleOn|databases/PgBouncer/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/PgBouncer/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/PgBouncer/mode + loader: getAdminOptions|databases/PgBouncer/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/PgBouncer/mode + label: Database Mode + watcher: + func: onDatabaseModeChange + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + label: Replica number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/PgBouncer/mode - fetch: getAdminOptions|databases/PgBouncer/mode - hasDescription: true - if: isToggleOn|databases/PgBouncer/mode - label: - text: labels.database.mode - onChange: onDatabaseModeChange - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: isEqualToModelPathValue|Replicaset|/spec/mode - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine Profile + showLabels: true + type: block-layout + - label: Database Reference Name + schema: schema/properties/spec/properties/database/properties/databaseName + type: input + - loader: getAppBindings|postgres + label: Select Database Reference + watcher: + func: onRefChange + paths: + - temp/pgRef + refresh: true + validation: + type: required + schema: temp/pgRef + type: select + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - label: - text: labels.databaseref.name - schema: - $ref: schema#/properties/spec/properties/database/properties/databaseName + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - fetch: getAppBindings|postgres - label: - text: labels.databaseref.select - onChange: onRefChange - refresh: true - required: true - schema: - $ref: discriminator#/pgRef + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - label: Sync Users + schema: schema/properties/spec/properties/database/properties/syncUsers + type: switch + - isHorizontal: true + if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + options: + - description: Shared + text: Shared + value: Shared + - description: Dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default type: select - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - pgRef: - default: {} - type: object - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - label: - text: labels.sync_users_question - schema: - $ref: schema#/properties/spec/properties/database/properties/syncUsers + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled + # sortable: true type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|tls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default + type: switch + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - elements: - - if: isToggleOn|tls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-pgbouncer-editor-options/ui/functions.js b/charts/kubedbcom-pgbouncer-editor-options/ui/functions.js index 094c8412e3..989d724bb0 100644 --- a/charts/kubedbcom-pgbouncer-editor-options/ui/functions.js +++ b/charts/kubedbcom-pgbouncer-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,727 +317,742 @@ const modeDetails = { }, } -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, - }, - }, - } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, - ) - const resources = (resp && resp.data && resp.data.items) || [] - - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] - } -} -function onRefChange({ discriminator, getValue, commit }) { - const ref = getValue(discriminator, '/pgRef') || {} - commit('wizard/model$update', { - path: `/spec/database/databaseRef/name`, - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: `/spec/database/databaseRef/namespace`, - value: ref.namespace || '', - force: true, - }) -} -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -const onDatabaseModeChange = ({ model, getValue, commit }) => { - const databaseMode = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/replicas', - value: databaseMode === 'Standalone' ? 1 : 3, - force: true, - }) -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('pgRef', {}) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + async function getAppBindings(type) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const queryParams = { + filter: { + items: { + metadata: { name: null, namespace: null }, + spec: { type: null }, }, }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] } - } catch (e) { - console.log(e) - } - return [] -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } - }) - .filter((val) => !!val) - } - return array -} - -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory - } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue - } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + queryParams, + ) + const resources = (resp && resp.data && resp.data.items) || [] + + const fileredResources = resources + .filter((item) => item.spec?.type === `kubedb.com/${type}`) + .map((item) => { + const name = item.metadata?.name || '' + const namespace = item.metadata?.namespace || '' + return { + text: `${namespace}/${name}`, + value: { + name: name, + namespace: namespace, + }, + } + }) + return fileredResources + } catch (e) { + console.log(e) + return [] } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) + function onRefChange() { + const ref = getValue(discriminator, '/pgRef') || {} commit('wizard/model$update', { - path: comparePath, - value: memory, + path: `/spec/database/databaseRef/name`, + value: ref.name || '', force: true, }) - return memory - } else { commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: `/spec/database/databaseRef/namespace`, + value: ref.namespace || '', force: true, }) + } + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } + + const onDatabaseModeChange = () => { + const databaseMode = getValue(model, '/spec/mode') commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/replicas', + value: databaseMode === 'Standalone' ? 1 : 3, force: true, }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + if (available.length) { + array = available.map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } + }) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array + } -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory + } else { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: reqCommitPath, + value: cpu, force: true, }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/PgBouncer/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/PgBouncer/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/PgBouncer/mode/available') || [] - if (arr.length) defMode = arr[0] - } + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, + path: commitPath, + value: val, force: true, }) } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue } - if (!features.includes('backup')) { + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} - -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } + commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!getValue(model, `/spec/admin/databases/PgBouncer/mode/toggle`)) { + let defMode = getDefault('databases/PgBouncer/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/PgBouncer/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + setDiscriminatorValue('/bundleApiLoaded', true) } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } + + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const isAlertToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'alert', - ) - return isMonitorEnabled && isAlertToggleEnabled -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const isAlertToggleEnabled = isToggleOn('alert', + ) + return isMonitorEnabled && isAlertToggleEnabled + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers', + ) + return isTlsEnabled && isIssuerToggleEnabled + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } -} -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } + + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + showAdditionalSettings, + initBundle, + returnFalse, + getAppBindings, + onRefChange, + isVariantAvailable, + isEqualToModelPathValue, + showAuthPasswordField, + getNamespaces, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + isMachineNotCustom, + isMachineCustom, + updateAlertValue, + onDatabaseModeChange, + getNodeTopology, + filterNodeTopology, + getAdminOptions, + isToggleOn, + showAlerts, + showIssuer, + onBackupSwitch, + setMonitoring, + onAuthChange, + isConfigDatabaseOn, + clearConfiguration, + setBackup, + getDefault, + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - showAdditionalSettings, - initBundle, - returnFalse, - getAppBindings, - onRefChange, - isVariantAvailable, - isEqualToModelPathValue, - showAuthPasswordField, - getNamespaces, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - isMachineNotCustom, - isMachineCustom, - updateAlertValue, - onDatabaseModeChange, - getNodeTopology, - filterNodeTopology, - getAdminOptions, - isToggleOn, - showAlerts, - showIssuer, - onBackupSwitch, - setMonitoring, - onAuthChange, - isConfigDatabaseOn, - clearConfiguration, - setBackup, - getDefault, } diff --git a/charts/kubedbcom-pgbouncer-editor/ui/edit-ui.yaml b/charts/kubedbcom-pgbouncer-editor/ui/edit-ui.yaml index 3f77819282..869e7900c7 100644 --- a/charts/kubedbcom-pgbouncer-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-pgbouncer-editor/ui/edit-ui.yaml @@ -1,871 +1,444 @@ -steps: -- form: - discriminator: - createAuthSecret: - type: boolean - password: - type: string - pgRef: - default: {} - type: object - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - fetch: getResources|core|v1|namespaces - label: - text: labels.namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - disableUnselect: true - disabled: true - fetch: getPgBouncerVersions|catalog.kubedb.com|v1alpha1|pgbouncerversions - label: - text: labels.database.version - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/version - type: select - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/deletionPolicy - type: radio - - label: - text: labels.sync_users_question - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/database/properties/syncUsers - type: switch - - label: - text: labels.databaseref.name - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/database/properties/databaseName - type: input - - fetch: getAppBindings|postgres - label: - text: labels.databaseref.select - onChange: onRefChange - refresh: true - required: true - schema: - $ref: discriminator#/pgRef - type: select - - label: - text: labels.database.secret - type: label-element - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/authSecret/properties/name - type: input - - label: - text: labels.autoops - type: label-element - - label: - text: labels.disable_autoops - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/autoOps/properties/disabled - type: switch - type: single-step-form - id: basic - title: steps.0.label -- form: - elements: - - label: - text: labels.connection_pool.authType - options: - - text: md5 - value: md5 - - text: scram - value: scram - - text: cert - value: cert - - text: any - value: trust - - text: hba - value: hba - - text: pam - value: pam - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/authType - type: select - - label: - text: labels.connection_pool.poolMode - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/poolMode - type: input - - label: - text: labels.connection_pool.defaultPoolSize - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/defaultPoolSize - type: input - - label: - text: labels.connection_pool.minPoolSize - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/minPoolSize - type: input - - label: - text: labels.connection_pool.reservePoolSize - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/reservePoolSize - type: input - - label: - text: labels.connection_pool.reservePoolTimeoutSeconds - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/reservePoolTimeoutSeconds - type: input - - label: - text: labels.connection_pool.ignoreStartupParameters - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/ignoreStartupParameters - type: input - - label: - text: labels.connection_pool.maxClientConnections - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/maxClientConnections - type: input - - label: - text: labels.connection_pool.maxDBConnections - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/maxDBConnections - type: input - - label: - text: labels.connection_pool.maxUserConnections - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/maxUserConnections - type: input - - label: - text: labels.connection_pool.port - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/port - type: input - - label: - text: labels.connection_pool.statsPeriodSeconds - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool/properties/statsPeriodSeconds - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/connectionPool - type: single-step-form - id: connection-pool - title: steps.1.label -- form: - discriminator: - activeDatabaseMode: - default: Standalone - type: string - elements: - - computed: setDatabaseMode - hasDescription: true - label: - text: labels.database.mode - onChange: onDatabaseModeChange - options: - - description: options.database.mode.Standalone.description - text: options.database.mode.Standalone.label - value: Standalone - - description: options.database.mode.Cluster.description - text: options.database.mode.Cluster.label - value: Cluster - schema: - $ref: discriminator#/activeDatabaseMode - type: radio - - if: isEqualToDatabaseMode|Cluster - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/replicas - type: input - type: single-step-form - id: topology - title: steps.2.label -- form: - elements: - - alias: reusable_health_checker - chart: - name: uibytebuildersdev-component-health-checker - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/healthChecker - type: reusable-element - type: single-step-form - id: health-checker - title: steps.3.label -- form: - discriminator: - configureTLS: - default: true - type: boolean - elements: - - computed: isValueExistInModel|/resources/kubedbComPgBouncer/spec/tls - disabled: true - label: - text: labels.enable_tls - onChange: onTlsConfigureChange - schema: - $ref: discriminator#/configureTLS - type: switch - - disabled: true - elements: - - computed: setSSLMode - label: - text: labels.ssl_mode - options: - - text: allow - value: allow - - text: prefer - value: prefer - - text: require - value: require - - text: verify-ca - value: verify-ca - - text: verify-full - value: verify-full - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/sslMode - type: select - - elements: - - computed: setApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - title: steps.4.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComPgBouncer/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComPgBouncer/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPgBouncer/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPgBouncer/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - elements: - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - id: pod-template - title: steps.6.label -- form: - elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.7.label -- form: +type: multi-step-form +step: + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - discriminator: - setCustomConfig: - type: string - elements: - - computed: returnStringYes - disabled: true - label: - text: labels.setCustomConfig - onChange: onSetCustomConfigChange + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/setCustomConfig - type: radio - - discriminator: - configuration: - type: string - configurationSource: - type: string + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - computed: setConfigurationSource - disabled: true - label: - text: labels.custom_config - onChange: onConfigurationSourceChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/properties/configurationSource - type: radio - - allowUserDefinedOption: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSource - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/configSecret/properties/name - type: select - - computed: setConfigurationForEdit - if: isEqualToDiscriminatorPath|create-new-config|/configurationSource - label: - text: labels.user_conf - onChange: onConfigurationChangeEdit - schema: - $ref: discriminator#/properties/configuration - type: editor - if: isEqualToDiscriminatorPath|yes|/setCustomConfig - type: single-step-form - type: single-step-form - type: single-step-form - id: custom-config - title: steps.8.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + # pgbouncer mode + - type: block-layout + label: PgBouncer + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComPgBouncerAutoscaler/spec/compute/pgbouncer/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|pgbouncer + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|pgbouncer + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|pgbouncer + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComPgBouncer/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComPgBouncerAutoscaler/spec/compute/pgbouncer/trigger - label: - text: Trigger + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComPgBouncer/spec/monitor/agent elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|pgbouncer - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|pgbouncer - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|pgbouncer - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer/properties/controlledResources - type: multiselect - label: - text: pgbouncer - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/pgbouncer - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgBouncerAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -type: multi-step-form + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPgBouncer/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPgBouncer/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: + type: input + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComPgBouncer/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true \ No newline at end of file diff --git a/charts/kubedbcom-pgbouncer-editor/ui/functions.js b/charts/kubedbcom-pgbouncer-editor/ui/functions.js index 70287e11e4..f04c1feba4 100644 --- a/charts/kubedbcom-pgbouncer-editor/ui/functions.js +++ b/charts/kubedbcom-pgbouncer-editor/ui/functions.js @@ -1,2190 +1,817 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + let autoscaleType = '' + let dbDetails = {} + + function isConsole() { + const isKube = isKubedb() + + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + return !isKube + } + + function isKubedb() { + return !!storeGet('/route/params/actions') + } + + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name') || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgbouncers/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} -function setAddressType({ model, getValue }) { - const value = getValue(model, '/resources/kubedbComPgBouncer/spec/useAddressType') - - if (!value) { - return 'DNS' - } - - return value -} - -// ************************* Basic Info ********************************************** -async function getPgBouncerVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] - } -} - -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue }) { - const replicas = getValue(model, '/resources/kubedbComPgBouncer/spec/replicas') - - return replicas === 1 ? 'Standalone' : 'Cluster' -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} - -const onDatabaseModeChange = ({ discriminator, getValue, commit }) => { - const databaseMode = getValue(discriminator, '/activeDatabaseMode') - - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/replicas', - value: databaseMode === 'Standalone' ? 1 : 3, - force: true, - }) -} - -// ************************** TLS ******************************88 - -function setApiGroup() { - return 'cert-manager.io' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComPgBouncer/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComPgBouncer/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComPgBouncer/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComPgBouncer/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } - - if (!url) return [] - - try { - const resp = await axios.get(url) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComPgBouncer/spec/sslMode') - return val || 'require' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/tls', - value: { issuerRef: {}, certificates: [] }, + path: `/metadata/release/namespace`, + value: namespace, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/monitor', - value: {}, + path: `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name`, + value: name, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/monitor/prometheus/exporter', - value: {}, + path: `/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/monitor/prometheus/exporter') } -} -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComPgBouncer/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComPgBouncer/spec/init/script') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + const resources = (resp && resp.data && resp.data.items) || [] -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/init/waitForInitialRestore', - value: false, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComPgBouncer/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComPgBouncer/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComPgBouncer/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComPgBouncer/spec/init/script/secret/secretName') - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/init/script/secret') - - if (!valueExists(model, getValue, '/resources/kubedbComPgBouncer/spec/init/script/configMap')) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComPgBouncer/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/init/script/secret', - value: { - secretName: '', - }, - }) + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name', + ) } } -} -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return repositoryChoise === value -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) + const resources = (resp && resp.data && resp.data.items) || [] - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name') || + '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, + path: '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/name', + value: modifiedName, + force: true, }) - } - } -} -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute', ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration -// schedule bakcup + async function fetchTopologyMachines() { + const instance = hasAnnotations() -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComPgBouncerAnnotations = - getValue(model, '/resources/kubedbComPgBouncer/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComPgBouncerAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) - return { - stashAppscodeComBackupConfiguration, - isBluePrint, + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } -} -function deleteKubeDbComPgBouncerDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComPgBouncer/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubeDbComPgBouncerDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComPgBouncer/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' } - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComPgBouncer annotation - deleteKubeDbComPgBouncerDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } + function setApplyToIfReady() { + return 'IfReady' } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -// invoker form -function initBackupInvoker({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration) return 'backupConfiguration' - else if (isBluePrint) return 'backupBlueprint' - else return undefined -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model }) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - if (backupInvoker === 'backupConfiguration') { - // delete annotation and create backup config object - deleteKubeDbComPgBouncerDbAnnotation(getValue, model, commit) - const dbName = getValue(model, '/metadata/release/name') + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] - if (!valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - // delete backup configuration object and create the annotation - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - addKubeDbComPgBouncerDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - '', - ) + return !!instance } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } + function hasNoAnnotations() { + return !hasAnnotations() } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComPgBouncer/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComPgBouncerDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComPgBouncerDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} + function setAllowedMachine(minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') + if (minmax === 'min') return mn + else return mx + } - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComPgBouncer/metadata/annotations') || {} - const newAnnotations = {} + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComPgBouncer/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComPgBouncer/spec/metadata/labels') - const agent = getValue(model, '/resources/kubedbComPgBouncer/spec/monitor/agent') + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) + return dependantIndex === -1 ? machines : filteredMachine } -} -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] - const agent = getValue(model, '/resources/kubedbComPgBouncer/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComPgBouncer/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute/${type}` - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, force: true, }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, force: true, }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) - } - - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComPgBouncer/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComPgBouncer/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') + commit('wizard/model$update', { + path: annoPath, + value: annotations, + force: true, + }) + } + } - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute/${type}/controlledResources` commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), + path: path, + value: list, force: true, }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') + return list } -} -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComPgBouncer/spec/init/initialized') - watchDependency('model#/resources/kubedbComPgBouncer/spec/init/initialized') - return !!initialized -} + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] + } -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) + } -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') + /****** Monitoring *********/ + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - if (owner && cluster && namespace) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, - }, - }, - }, + params: { filter: { items: { metadata: { name: null } } } }, }, ) - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) - }) + const resources = (resp && resp.data && resp.data.items) || [] - filteredSecrets.map((item) => { + resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' item.text = name item.value = name return true }) - return filteredSecrets + return resources } catch (e) { console.log(e) + return [] } } - return [] -} -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } + + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/secret_config', + path: '/resources/kubedbComPgBouncer/spec/monitor', value: {}, force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/monitor') } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/configSecret/name', - value: configSecretName, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/user.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function onConfigurationChangeEdit({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - - commit('wizard/model$update', { - path: '/resources/secret_config/data/pgbouncer.ini', - value: btoa(value), - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus } - return 'use-existing-config' -} -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/user.conf') -} - -function setConfigurationForEdit({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/pgbouncer.ini') - return atob(value) -} - -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/user.conf') - return atob(value) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComPgBouncer/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComPgBouncer/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit( + 'wizard/model$delete', + '/resources/kubedbComPgBouncer/spec/monitor/prometheus/exporter', + ) + } } -} -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/pgbounceropsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} - -const getAppbinding = async ({ axios, storeGet, getValue, watchDependency, rootModel }) => { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const group = 'appcatalog.appscode.com' - const version = 'v1alpha1' - const resource = 'appbindings' - - watchDependency('rootModel#/databaseRef/namespace') - - const namespace = getValue(rootModel, '/databaseRef/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function onRefChange({ discriminator, getValue, commit }) { - const ref = getValue(discriminator, '/pgRef') || {} - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/database/databaseRef/name', - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComPgBouncer/spec/database/databaseRef/namespace', - value: ref.namespace || '', - force: true, - }) -} - -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, - }, - }, + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, - ) - const resources = (resp && resp.data && resp.data.items) || [] - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] - } -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComPgBouncer/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComPgBouncer/spec/metadata/labels') -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + const agent = getValue(model, '/resources/kubedbComPgBouncer/spec/monitor/agent') - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace', - value: namespace, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, force: true, }) } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComPgBouncer/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - const resources = (resp && resp.data && resp.data.items) || [] + const isKube = !!storeGet('/route/params/actions') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/pgbounceropsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgbouncers/${name}`, + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name', ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) } } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') - - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } } - clearSpecModel({ commit }, verd) - return type === verd && spec -} -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/${autoscaleType}/cluster`, - ) + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name') || - '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute') -} -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name', - ) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setApplyToIfReady() { - return 'IfReady' -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) } + + return ans } -} -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComPgBouncer/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) + + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') + + if (!configMapName) return [] - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) + + const configMaps = (resp && resp.data && resp.data.data) || {} - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) + + return configMapKeys } catch (e) { console.log(e) return [] } } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + const secrets = (resp && resp.data && resp.data.items) || [] - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } + } - return dependantIndex === -1 ? machines : filteredMachine -} + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComPgBouncer/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - return !!instance -} + if (!secretName) return [] -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComPgBouncerAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] + const secret = (resp && resp.data && resp.data.data) || {} - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComPgBouncerAutoscaler/spec/compute/${type}` + return secretKeys + } catch (e) { + console.log(e) + return [] + } + } - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + function returnFalse() { + return false } -} -return { - isRancherManaged, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - isVariantAvailable, - fetchJsons, - getAppbinding, - onDatabaseModeChange, - setDatabaseMode, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - setAddressType, - getPgBouncerVersions, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - valueExists, - onConfigurationChangeEdit, - setConfigurationForEdit, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComPgBouncerDbAnnotation, - addKubeDbComPgBouncerDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - setConfigurationForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - disableInitializationSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - onRefChange, - getAppBindings, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + return { + isConsole, + isKubedb, + getDbDetails, + getNamespaces, + isRancherManaged, + onNamespaceChange, + getDbs, + initMetadata, + fetchTopologyMachines, + setTrigger, + setApplyToIfReady, + hasAnnotations, + hasNoAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + setControlledResources, + fetchNodeTopology, + isNodeTopologySelected, + showOpsRequestOptions, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + } } diff --git a/charts/kubedbcom-pgpool-editor-options/ui/create-ui.yaml b/charts/kubedbcom-pgpool-editor-options/ui/create-ui.yaml index 52fdd164cf..8923d8d9b8 100644 --- a/charts/kubedbcom-pgpool-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-pgpool-editor-options/ui/create-ui.yaml @@ -1,311 +1,291 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - postgresRef: - default: {} - type: object - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Pgpool/versions - if: isToggleOn|databases/Pgpool/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Pgpool/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Pgpool/versions + if: + type: function + name: isToggleOn|databases/Pgpool/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Pgpool/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Pgpool/mode + loader: getAdminOptions|databases/Pgpool/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/Pgpool/mode + label: Database Mode + watcher: + func: onModeChange + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + label: Replica Number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/Pgpool/mode - fetch: getAdminOptions|databases/Pgpool/mode - hasDescription: true - if: isToggleOn|databases/Pgpool/mode - label: - text: labels.database.mode - onChange: onModeChange - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: isEqualToModelPathValue|Replicaset|/spec/mode - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine Profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage Class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - loader: getAppBindings|postgres + label: Select Database Reference + watcher: + func: onRefChange + paths: + - discriminator/postgresRef + refresh: true + validation: + type: required + schema: discriminator/postgresRef + type: select + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - fetch: getAppBindings|postgres - label: - text: labels.postgresRef.label - onChange: onRefChange|postgresRef - refresh: true - required: true - schema: - $ref: discriminator#/postgresRef + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name type: select - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - label: - text: Sync Users? - schema: - $ref: schema#/properties/spec/properties/syncUsers + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - label: Sync Users + schema: schema/properties/spec/properties/syncUsers + type: switch + - isHorizontal: true + if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + options: + - description: Shared + text: Shared + value: Shared + - description: Dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|tls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default + type: switch + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - elements: - - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - if: isToggleOn|tls - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-pgpool-editor-options/ui/functions.js b/charts/kubedbcom-pgpool-editor-options/ui/functions.js index f84f6bf97d..fcc6dfb54f 100644 --- a/charts/kubedbcom-pgpool-editor-options/ui/functions.js +++ b/charts/kubedbcom-pgpool-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -314,966 +316,976 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('postgresRef', {}) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('monitoring', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: comparePath, - value: memory, + path: commitPath, + value: val, force: true, }) - return memory - } else { + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } + } + + function updateAgentValue(val) { commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', force: true, }) + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} - -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function ifCapiProviderIsNotEmpty() { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + function showMultiselectZone() { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (val === 'capz' && ifDedicated()) return true + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + function showSelectZone() { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + function ifDedicated() { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + function dedicatedOnChange() { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + function ifZones() { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + function zonesOnChange() { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } + + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { + commit('wizard/model$update', { + path: '/spec/admin/storageClasses/default', + value: storageClass, + force: true, }) - return val - } catch (e) { - console.log(e) - return [] } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const namespace = getValue(model, '/metadata/release/namespace') + const cluster = storeGet('/route/params/cluster') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, }) - url = url.slice(0, -1) } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val } catch (e) { console.log(e) - return [] } - } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const namespace = getValue(model, '/metadata/release/namespace') - const cluster = storeGet('/route/params/cluster') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!getValue(model, `/spec/admin/databases/Pgpool/mode/toggle`)) { + let defMode = getDefault('databases/Pgpool/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Pgpool/mode/available') || [] + if (arr.length) defMode = arr[0] + } commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/mode', + value: defMode, force: true, }) } - } catch (e) { - console.log(e) - } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Pgpool/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Pgpool/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Pgpool/mode/available') || [] - if (arr.length) defMode = arr[0] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) - } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) - } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + setDiscriminatorValue('/bundleApiLoaded', true) } - setDiscriminatorValue('/bundleApiLoaded', true) -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` - commit('wizard/model$update', { - path: path, - value: returnArray[0], - force: true, - }) + return returnArray } - return returnArray -} - -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - const options = getValue(model, `/spec/admin/${type}/available`) || [] + const options = getValue(model, `/spec/admin/${type}/available`) || [] - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) - } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, watchDependency, discriminator }, 'alert') - ) -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return ( + isMonitorEnabled && isToggleOn('alert') + ) + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + function clearArbiterHidden() { + commit('wizard/model$update', { + path: `/spec/arbiter/enabled`, + value: false, + force: true, + }) -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + commit('wizard/model$update', { + path: `/spec/hidden/enabled`, + value: false, + force: true, + }) + } -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } + + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } -} -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function onModeChange({ model, getValue, commit }) { - const dbMode = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/replicas', - value: dbMode === 'Replicaset' ? 3 : 1, - force: true, - }) -} + function onModeChange() { + const dbMode = getValue(model, '/spec/mode') + commit('wizard/model$update', { + path: '/spec/replicas', + value: dbMode === 'Replicaset' ? 3 : 1, + force: true, + }) + } -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, + async function getAppBindings(type) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const queryParams = { + filter: { + items: { + metadata: { name: null, namespace: null }, + spec: { type: null }, + }, }, - }, + } + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + queryParams, + ) + const resources = (resp && resp.data && resp.data.items) || [] + + const fileredResources = resources + .filter((item) => item.spec?.type === `kubedb.com/${type}`) + .map((item) => { + const name = item.metadata?.name || '' + const namespace = item.metadata?.namespace || '' + return { + text: `${namespace}/${name}`, + value: { + name: name, + namespace: namespace, + }, + } + }) + return fileredResources + } catch (e) { + console.log(e) + return [] + } } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, - ) - const resources = (resp && resp.data && resp.data.items) || [] - - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] + + function onRefChange(type) { + const ref = getValue(discriminator, `/${type}`) || {} + commit('wizard/model$update', { + path: `/spec/${type}/name`, + value: ref.name || '', + force: true, + }) + commit('wizard/model$update', { + path: `/spec/${type}/namespace`, + value: ref.namespace || '', + force: true, + }) } -} -function onRefChange({ discriminator, getValue, commit }, type) { - const ref = getValue(discriminator, `/${type}`) || {} - commit('wizard/model$update', { - path: `/spec/${type}/name`, - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: `/spec/${type}/namespace`, - value: ref.namespace || '', - force: true, - }) -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + returnFalse, + initBundle, + getNamespaces, + updateAlertValue, + getAdminOptions, + isToggleOn, + showAlerts, + getNodeTopology, + clearArbiterHidden, + showHidden, + isConfigDatabaseOn, + notEqualToDatabaseMode, + filterNodeTopology, + onAuthChange, + setMonitoring, + isMachineNotCustom, + isMachineCustom, + showIssuer, + showArbiter, + clearConfiguration, + onBackupSwitch, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + onModeChange, + getAppBindings, + onRefChange, + setBackup, + showAdditionalSettings, + getDefault, + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - returnFalse, - initBundle, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - onModeChange, - getAppBindings, - onRefChange, - setBackup, - showAdditionalSettings, - getDefault, } diff --git a/charts/kubedbcom-pgpool-editor/ui/edit-ui.yaml b/charts/kubedbcom-pgpool-editor/ui/edit-ui.yaml index 368b54d6f3..ffb6fdf493 100644 --- a/charts/kubedbcom-pgpool-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-pgpool-editor/ui/edit-ui.yaml @@ -1,460 +1,444 @@ -steps: -- form: - discriminator: - dbDetails: - default: false - type: boolean +type: multi-step-form +step: + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array - elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComPgpoolAutoscaler/spec/compute/pgpool/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string - elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|pgpool - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|pgpool - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|pgpool - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/controlledResources - type: multiselect - label: - text: pgpool - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines + elements: + # pgpool mode + - type: block-layout + label: Pgpool + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComPgpoolAutoscaler/spec/compute/pgpool/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|pgpool + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|pgpool + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|pgpool + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/pgpool/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComPgpoolAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComPgpool/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComPgpool/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComPgpool/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/agent + isHorizontal: true + options: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComPgpool/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPgpool/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPgpool/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPgpool/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPgpool/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -type: multi-step-form + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComPgpool/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true diff --git a/charts/kubedbcom-pgpool-editor/ui/functions.js b/charts/kubedbcom-pgpool-editor/ui/functions.js index eea703407d..582ff95325 100644 --- a/charts/kubedbcom-pgpool-editor/ui/functions.js +++ b/charts/kubedbcom-pgpool-editor/ui/functions.js @@ -1,54 +1,119 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + let autoscaleType = '' + let dbDetails = {} + + function isConsole() { + const isKube = isKubedb() + + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } + } + + return !isKube + } + + function isKubedb() { + return !!storeGet('/route/params/actions') + } + + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') && + !!getValue(discriminator, '/autoscalingType') ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } -} -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) + + const resources = (resp && resp.data && resp.data.items) || [] + + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, { params: { filter: { items: { metadata: { name: null } } } }, }, @@ -56,1336 +121,578 @@ async function getResources({ axios, storeGet }, group, version, resource) { const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + return { + text: name, + value: name, + } }) - return resources - } catch (e) { - console.log(e) - return [] } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgpools/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) } - return ans -} + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + // delete the other type object from model + if (type === 'compute') + commit('wizard/model$delete', '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/storage') + if (type === 'storage') + commit('wizard/model$delete', '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute') } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name', + ) } - }) -} - -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} -function setAddressType({ model, getValue }) { - const value = getValue(model, '/resources/kubedbComPgpool/spec/useAddressType') - - if (!value) { - return 'DNS' + return [] } - return value -} - -// ************************* Basic Info ********************************************** -async function getPgpoolVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] + return list } -} - -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue }) { - const replicas = getValue(model, '/resources/kubedbComPgpool/spec/replicas') - - return replicas === 1 ? 'Standalone' : 'Cluster' -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} - -const onDatabaseModeChange = ({ discriminator, getValue, commit }) => { - const databaseMode = getValue(discriminator, '/activeDatabaseMode') - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/replicas', - value: databaseMode === 'Standalone' ? 1 : 3, - force: true, - }) -} - -// ************************** TLS ******************************88 - -function setApiGroup() { - return 'cert-manager.io' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComPgpool/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComPgpool/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComPgpool/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComPgpool/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' } - if (!url) return [] + function setApplyToIfReady() { + return 'IfReady' + } - try { - const resp = await axios.get(url) + async function fetchTopologyMachines() { + const instance = hasAnnotations() - const resources = (resp && resp.data && resp.data.items) || [] + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + function setAllowedMachine(minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' - return !!(resp && resp.length) -} + if (minmax === 'min') return mn + else return mx + } -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` - return !resp -} + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComPgpool/spec/sslMode') - return val || 'require' -} + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/sslMode') - } -} -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/monitor') + return dependantIndex === -1 ? machines : filteredMachine } - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/monitor/prometheus/exporter') + return !!instance } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} + function hasNoAnnotations() { + return !hasAnnotations() + } -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComPgpool/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComPgpool/spec/init/script') + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute/${type}` -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, force: true, }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: annotations, force: true, }) } } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComPgpool/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') + const resources = (resp && resp.data && resp.data.items) || [] - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComPgpool/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/init/script', - value: initScript, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/init/script') + return resources + } catch (e) { + console.log(e) + return [] + } + } + + /****** Monitoring *********/ - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, + path: '/resources/kubedbComPgpool/spec/monitor', + value: {}, + force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/monitor') + } + + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', + force: true, + }) + } + + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, + path: '/resources/kubedbComPgpool/spec/monitor/prometheus/exporter', + value: {}, force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/monitor/prometheus/exporter') } } -} -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComPgpool/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComPgpool/spec/init/script/secret/secretName') + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComPgpool/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/init/script/secret') + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComPgpool/spec/metadata/labels') - if (!valueExists(model, getValue, '/resources/kubedbComPgpool/spec/init/script/configMap')) { + const agent = getValue(model, '/resources/kubedbComPgpool/spec/monitor/agent') + + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/init/script/configMap', - value: { - name: '', - }, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, }) } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/init/script/configMap') + } - if (!valueExists(model, getValue, '/resources/kubedbComPgpool/spec/init/script/secret')) { + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComPgpool/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/init/script/secret', - value: { - secretName: '', - }, + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, }) + + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } } -} -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} + const isKube = !!storeGet('/route/params/actions') -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/pgpoolopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name', + ) + } + } -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } + } - return repositoryChoise === value -} + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } + } -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) - } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule bakcup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComPgpoolAnnotations = - getValue(model, '/resources/kubedbComPgpool/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComPgpoolAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - } -} - -function deleteKubeDbComPgpoolDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComPgpool/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubeDbComPgpoolDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComPgpool/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComPgpool annotation - deleteKubeDbComPgpoolDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } -} -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -// invoker form -function initBackupInvoker({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration) return 'backupConfiguration' - else if (isBluePrint) return 'backupBlueprint' - else return undefined -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model }) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - - if (backupInvoker === 'backupConfiguration') { - // delete annotation and create backup config object - deleteKubeDbComPgpoolDbAnnotation(getValue, model, commit) - const dbName = getValue(model, '/metadata/release/name') - - if (!valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - // delete backup configuration object and create the annotation - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - addKubeDbComPgpoolDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - '', - ) - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }) - } - } -} -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComPgpool/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComPgpoolDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComPgpoolDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComPgpool/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComPgpool/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) + return ans } -} -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComPgpool/spec/metadata/labels') + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComPgpool/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - } -} -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComPgpool/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComPgpool/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) - } - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) - } - - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComPgpool/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComPgpool/spec/authSecret') - - return !authSecret -} -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComPgpool/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} + if (!configMapName) return [] -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComPgpool/spec/init/initialized') - watchDependency('model#/resources/kubedbComPgpool/spec/init/initialized') - return !!initialized -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} + const configMaps = (resp && resp.data && resp.data.data) || {} -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') + return configMapKeys + } catch (e) { + console.log(e) + return [] + } } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - if (owner && cluster && namespace) { try { const resp = await axios.get( `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, { params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, - }, - }, + filter: { items: { metadata: { name: null }, type: null } }, }, }, ) @@ -1393,11 +700,7 @@ async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) const secrets = (resp && resp.data && resp.data.items) || [] const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] + const validType = ['kubernetes.io/service-account-token', 'Opaque'] return validType.includes(item.type) }) @@ -1410,798 +713,90 @@ async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) return filteredSecrets } catch (e) { console.log(e) + return [] } } - return [] -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/user.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function onConfigurationChangeEdit({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - - commit('wizard/model$update', { - path: '/resources/secret_config/data/pgpool.ini', - value: btoa(value), - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/user.conf') -} - -function setConfigurationForEdit({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/pgpool.ini') - return atob(value) -} - -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/user.conf') - return atob(value) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComPgpool/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - } -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/pgpoolopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} - -const getAppbinding = async ({ axios, storeGet, getValue, watchDependency, rootModel }) => { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const group = 'appcatalog.appscode.com' - const version = 'v1alpha1' - const resource = 'appbindings' - - watchDependency('rootModel#/databaseRef/namespace') - const namespace = getValue(rootModel, '/databaseRef/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function onRefChange({ discriminator, getValue, commit }) { - const ref = getValue(discriminator, '/pgRef') || {} - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/database/databaseRef/name', - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComPgpool/spec/database/databaseRef/namespace', - value: ref.namespace || '', - force: true, - }) -} - -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, - }, - }, - } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComPgpool/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', ) - const resources = (resp && resp.data && resp.data.items) || [] - - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] - } -} - -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) - - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace', - value: namespace, - force: true, - }) - } - } - - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - const resources = (resp && resp.data && resp.data.items) || [] + if (!secretName) return [] - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgpools/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) - } - } - - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') - - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' - } - clearSpecModel({ commit }, verd) - return type === verd && spec -} - -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/${autoscaleType}/cluster`, - ) - } -} -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) + const secret = (resp && resp.data && resp.data.data) || {} - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute') -} + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name', - ) - } -} - -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} - -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} - -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, - }) - } - } -} - -function setMetadata({ storeGet, mode, commit }) { - const dbname = storeGet('/route/params/name') || '' - const namespace = storeGet('/route/query/namespace') || '' - if (mode === 'standalone-step') { - commit('wizard/model$update', { - path: '/metadata/release/name', - value: dbname, - force: true, - }) - commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, - force: true, - }) - } -} - -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) - - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) - - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + return secretKeys } catch (e) { console.log(e) return [] } } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComPgpoolAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComPgpoolAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + function returnFalse() { + return false } -} -return { - setMetadata, - isRancherManaged, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - isVariantAvailable, - fetchJsons, - getAppbinding, - onDatabaseModeChange, - setDatabaseMode, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - setAddressType, - getPgpoolVersions, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - valueExists, - onConfigurationChangeEdit, - setConfigurationForEdit, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComPgpoolDbAnnotation, - addKubeDbComPgpoolDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - setConfigurationForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - disableInitializationSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - onRefChange, - getAppBindings, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + return { + isConsole, + isKubedb, + showOpsRequestOptions, + isRancherManaged, + getNamespaces, + getDbs, + getDbDetails, + initMetadata, + onNamespaceChange, + fetchNodeTopology, + isNodeTopologySelected, + setControlledResources, + setTrigger, + setApplyToIfReady, + fetchTopologyMachines, + setAllowedMachine, + getMachines, + hasAnnotations, + hasNoAnnotations, + onMachineChange, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + } } diff --git a/charts/kubedbcom-postgres-editor-options/ui/create-ui.yaml b/charts/kubedbcom-postgres-editor-options/ui/create-ui.yaml index 0958a1de7e..259b6e4031 100644 --- a/charts/kubedbcom-postgres-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-postgres-editor-options/ui/create-ui.yaml @@ -1,414 +1,403 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Postgres/versions - if: isToggleOn|databases/Postgres/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Postgres/properties/versions/properties/default +step: +- type: single-step-form + elements: + - init: + type: func + value: initBundle + if: + type: function + name: returnFalse + label: '' + type: label-element + - disableUnselect: true + loader: getAdminOptions|databases/Postgres/versions + if: + type: function + name: isToggleOn|databases/Postgres/versions + label: labels.database.version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Postgres/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Postgres/mode + loader: getAdminOptions|databases/Postgres/mode + if: + type: function + name: isToggleOn|databases/Postgres/mode + label: labels.database.mode + watcher: + func: clearArbiterHidden + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: EqualToDatabaseMode|Cluster + label: labels.replicas + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - loader: getAppBindings + label: RemoteReplica SourceRef + validation: + type: required + schema: schema/properties/spec/properties/remoteReplica/properties/sourceRef type: select - - computed: getDefault|databases/Postgres/mode - fetch: getAdminOptions|databases/Postgres/mode - hasDescription: true - if: isToggleOn|databases/Postgres/mode - label: - text: labels.database.mode - onChange: clearArbiterHidden - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: EqualToDatabaseMode|Cluster - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/replicas + if: + type: function + name: EqualToDatabaseMode|RemoteReplica + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: labels.machine + schema: schema/properties/spec/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: labels.cpu + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: labels.memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory type: input + label: labels.machine_profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: labels.storage.class + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: showStorageSizeField + label: labels.storage.size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - fetch: getAppBindings - label: - text: RemoteReplica SourceRef - required: true - schema: - $ref: schema#/properties/spec/properties/remoteReplica/properties/sourceRef - type: select - if: EqualToDatabaseMode|RemoteReplica - type: single-step-form + - type: object-item + label: labels.labels.label + schema: schema/properties/spec/properties/labels + - type: object-item + label: labels.annotations.label + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: labels.deletionPolicy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: options.deletionPolicy.delete.label + value: Delete + - description: options.deletionPolicy.halt.description + text: options.deletionPolicy.halt.label + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: options.deletionPolicy.wipeOut.label + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: options.deletionPolicy.doNotTerminate.label + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: labels.password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + hasCopy: true + schema: schema/properties/spec/properties/configuration + type: editor + - init: + type: func + value: getDefault|pointInTimeRecovery + if: + type: function + name: isToggleOn|pointInTimeRecovery + label: Point in-time Recovery? + schema: temp/recovery + type: switch - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + - label: Namespace + watcher: + func: setPointInTimeRecovery + paths: + - temp/refNamespace + validation: + type: required + schema: temp/refNamespace + type: input + - label: Name + watcher: + func: setPointInTimeRecovery + paths: + - temp/refDBName + validation: + type: required + schema: temp/refDBName type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + - customClass: mt-10 + label: Recovery Timestamp + schema: schema/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + if: + type: function + name: showRecovery + label: Point in-time Recovery + showLabels: true + type: block-layout + - if: + type: function + name: isToggleOn|deployment + label: labels.deployment.name + options: + - description: labels.deployment.shared + text: Shared + value: Shared + - description: labels.deployment.dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: labels.clusterTier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: labels.placement + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default type: select - - if: showStorageSizeField - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size - type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - recovery: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: labels.nodeTopology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + - if: + type: function + name: EqualToDatabaseMode|Cluster + label: Standby Mode + options: + - text: Hot + value: Hot + - text: Warm + value: Warm + schema: schema/properties/spec/properties/standbyMode + type: select + - if: + type: function + name: EqualToDatabaseMode|Cluster + label: Streaming Mode + options: + - text: Synchronous + value: Synchronous + - text: Asynchronous + value: Asynchronous + schema: schema/properties/spec/properties/streamingMode + type: select + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: labels.enable_monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name + - customClass: mt-10 + if: + type: function + name: showAlerts + label: labels.alert.options + options: + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled + # sortable: true type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - disable: showArchiverAlert + label: Enable Archiver? + watcher: + func: onArchiverChange + paths: + - schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default + schema: schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - computed: getDefault|pointInTimeRecovery - if: isToggleOn|pointInTimeRecovery - label: - text: Point in-time Recovery? - schema: - $ref: discriminator#/recovery + - if: + type: function + name: showArchiverAlert + label: The selected StorageClass does not support Archiver + type: warning + if: + type: function + name: showArchiver + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|tls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - discriminator: - refDBName: - type: string - refNamespace: - type: string - elements: - - label: - text: Namespace - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refNamespace - type: input - - label: - text: Name - onChange: setPointInTimeRecovery - required: true - schema: - $ref: discriminator#/refDBName - type: input - - customClass: mt-10 - label: - text: Recovery Timestamp - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp - type: input - if: showRecovery - label: - text: Point in-time Recovery - schema: - $ref: schema#/properties/spec/properties/init/properties/archiver - show_label: true - type: single-step-form - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: labels.clusterIssuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - refresh: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - - if: EqualToDatabaseMode|Cluster - label: - text: Standby Mode - options: - - text: Hot - value: Hot - - text: Warm - value: Warm - schema: - $ref: schema#/properties/spec/properties/standbyMode - type: select - - if: EqualToDatabaseMode|Cluster - label: - text: Streaming Mode - options: - - text: Synchronous - value: Synchronous - - text: Asynchronous - value: Asynchronous - schema: - $ref: schema#/properties/spec/properties/streamingMode - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - disabled: showArchiverAlert - label: - text: Enable Archiver? - onChange: onArchiverChange - schema: - $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default - type: switch - - alertInfo: - show: true - type: neutral - if: showArchiverAlert - label: - text: The selected StorageClass does not support Archiver - type: label-element - if: showArchiver - type: single-step-form - - elements: - - if: isToggleOn|tls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - type: single-step-form - - elements: - - if: isToggleOn|expose - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-postgres-editor-options/ui/functions.js b/charts/kubedbcom-postgres-editor-options/ui/functions.js index 0ce2a12bbd..a71142ccf6 100644 --- a/charts/kubedbcom-postgres-editor-options/ui/functions.js +++ b/charts/kubedbcom-postgres-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -319,1306 +321,1316 @@ const modeDetails = { }, } -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('recovery', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('refDBName', '') + setDiscriminatorValue('refNamespace', '') + setDiscriminatorValue('backup', false) + setDiscriminatorValue('monitoring', false) + + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - const projects = resp?.data?.status?.projects - if (projects) { - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - namespaces = projectsNamespace - } else { - namespaces = resp?.data?.status?.namespaces || [] + ) + const projects = resp?.data?.status?.projects + if (projects) { + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + namespaces = projectsNamespace + } else { + namespaces = resp?.data?.status?.namespaces || [] + } + return namespaces + } catch (e) { + console.log(e) + return [] } - return namespaces - } catch (e) { - console.log(e) - return [] } -} -function showRecovery({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/recovery') - const isRecoveryOn = getValue(discriminator, '/recovery') || '' - return isRecoveryOn -} + function showRecovery() { + // watchDependency('discriminator#/recovery') + const isRecoveryOn = getValue(discriminator, '/recovery') || '' + return isRecoveryOn + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} + function showAuthSecretField() { + return !showAuthPasswordField() + } -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } -async function getPostgresVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getPostgresVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, }, - }, - } + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - // keep only non deprecated versions - const filteredPostgresVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + // keep only non deprecated versions + const filteredPostgresVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - filteredPostgresVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredPostgresVersions -} + filteredPostgresVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredPostgresVersions + } -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const secrets = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + const secrets = (resp && resp.data && resp.data.items) || [] - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - } else { - array = machineList - .map((machine) => { + return filteredSecrets + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: comparePath, - value: memory, + path: commitPath, + value: val, force: true, }) - return memory - } else { + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } + } + + function updateAgentValue(val) { commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', force: true, }) + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} - -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + if (val === 'capz' && ifDedicated()) return true } -} - -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} - -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} - -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} - -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] - } + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb]`, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, watchDependency, discriminator }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb]`, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } } - const isChangeable = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, watchDependency, discriminator }, 'alert') - ) -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -let namespaces = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Postgres/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Postgres/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Postgres/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') } - if (!features.includes('tls')) { + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - if (!features.includes('binding')) { + + function clearArbiterHidden() { commit('wizard/model$update', { - path: '/spec/admin/expose/default', + path: `/spec/arbiter/enabled`, value: false, force: true, }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { + commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', + path: `/spec/hidden/enabled`, value: false, force: true, }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) } - namespaces = getNamespaces({ axios, storeGet }) - setDiscriminatorValue('/bundleApiLoaded', true) -} -function fetchNamespaces({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return namespaces -} + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + let namespaces = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` -async function getRecoveryNames({ getValue, model, watchDependency, storeGet, axios }, type) { - watchDependency(`model#/spec/init/archiver/${type}/namespace`) - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` - if (type === 'encryptionSecret') - url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - const options = [] - if (namespace) { try { const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } } catch (e) { console.log(e) } - } - return options -} -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } - - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} - -let archiverMap = [] -let archiverCalled = false - -function getAdminOptions({ getValue, model, watchDependency, axios, storeGet, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - - if (type === 'storageClasses' && !archiverCalled) { - getArchiverName({ axios, storeGet }) - } - - const options = getValue(model, `/spec/admin/${type}/available`) || [] - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} - -function showArchiver({ getValue, model }) { - return checkIfFeatureOn({ getValue, model }, 'archiver') -} - -async function getArchiverName({ axios, storeGet }) { - 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) - const via = getValue(model, '/spec/admin/archiver/via') - if (!isArchiverOn) { - commit('wizard/model$update', { - path: '/spec/archiverName', - value: '', - force: true, - }) - } else { - if (via === 'VolumeSnapshotter') { + if (!getValue(model, `/spec/admin/databases/Postgres/mode/toggle`)) { + let defMode = getDefault('databases/Postgres/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Postgres/mode/available') || [] + if (arr.length) defMode = arr[0] + } commit('wizard/model$update', { - path: '/spec/archiverName', - value: found.annotation, + path: '/spec/mode', + value: defMode, force: true, }) - } else { - const kind = getValue(model, '/metadata/resource/kind') + } + + if (!features.includes('tls')) { commit('wizard/model$update', { - path: '/spec/archiverName', - value: kind.toLowerCase(), + path: '/spec/admin/tls/default', + value: false, force: true, }) } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } + namespaces = getNamespaces() + setDiscriminatorValue('/bundleApiLoaded', true) } -} -function showArchiverAlert({ watchDependency, model, getValue, commit }) { - watchDependency('model#/spec/admin/storageClasses/default') + function fetchNamespaces() { + // watchDependency('discriminator#/bundleApiLoaded') + return namespaces + } - const mode = getValue(model, '/spec/mode') - if (mode === 'Standalone') return false + async function getRecoveryNames(type) { + // watchDependency(`model#/spec/init/archiver/${type}/namespace`) + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/spec/init/archiver/${type}/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${namespace}/repositories` + if (type === 'encryptionSecret') + url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + const options = [] + if (namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + } + return options + } - const via = getValue(model, '/spec/admin/archiver/via') + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } - if (via === 'VolumeSnapshotter') { - // toggle archiver to false when storageClass annotation not found - const stClass = getValue(model, '/spec/admin/storageClasses/default') - const found = archiverMap.find((item) => item.storageClass === stClass) - const show = !found?.annotation - if (show) { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, + path: path, + value: returnArray[0], force: true, }) - return true - } else onArchiverChange({ model, getValue, commit }) - } else onArchiverChange({ model, getValue, commit }) - return false -} + } -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + return returnArray } - const backupVal = getValue(model, '/spec/backup/tool') - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && val + let archiverMap = [] + let archiverCalled = false + + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') + + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName() + } + + const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } + + function showArchiver() { + return checkIfFeatureOn('archiver') + } + + async function getArchiverName() { + 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 isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + function onArchiverChange() { + 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) + const via = getValue(model, '/spec/admin/archiver/via') + + if (!isArchiverOn) { commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: '/spec/archiverName', + value: '', force: true, }) + } else { + if (via === 'VolumeSnapshotter') { + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) + } else { + const kind = getValue(model, '/metadata/resource/kind') + commit('wizard/model$update', { + path: '/spec/archiverName', + value: kind.toLowerCase(), + force: true, + }) + } } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + function showArchiverAlert() { + // watchDependency('model#/spec/admin/storageClasses/default') - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const via = getValue(model, '/spec/admin/archiver/via') - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (via === 'VolumeSnapshotter') { + // toggle archiver to false when storageClass annotation not found + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + if (show) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return true + } else onArchiverChange() + } else onArchiverChange() + return false + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = [] + return !validType.includes(modelPathValue) + } -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled } -} -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function EqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue === mode + } -function EqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue === mode -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function convertToLocal(input) { + const date = new Date(input) -function convertToLocal(input) { - const date = new Date(input) + if (isNaN(date.getTime())) { + return null + } - if (isNaN(date.getTime())) { - return null + return date.toString() } - return date.toString() -} - -function getComponentLogStats(snapshot) { - if (!snapshot || !snapshot.status || !snapshot.status.components) { - return null - } + function getComponentLogStats(snapshot) { + if (!snapshot || !snapshot.status || !snapshot.status.components) { + return null + } - const components = snapshot.status.components - const appKind = snapshot.spec?.appRef?.kind + const components = snapshot.status.components + const appKind = snapshot.spec?.appRef?.kind - if (appKind === 'MongoDB') { - for (const [key, value] of Object.entries(components)) { - if (key.endsWith('0') && value.logStats) { - return value.logStats + if (appKind === 'MongoDB') { + for (const [key, value] of Object.entries(components)) { + if (key.endsWith('0') && value.logStats) { + return value.logStats + } } } - } - if (components['wal'] && components['wal'].logStats) { - return components['wal'].logStats - } + if (components['wal'] && components['wal'].logStats) { + return components['wal'].logStats + } - return null -} + return null + } -async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const refNamespace = getValue(discriminator, '/refNamespace') - const refDBName = getValue(discriminator, '/refDBName') + async function setPointInTimeRecovery() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const refNamespace = getValue(discriminator, '/refNamespace') + const refDBName = getValue(discriminator, '/refDBName') - try { - const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` - const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` - const repositoriesResp = await axios.get(repositoriesUrl) - const snapshotsResp = await axios.get(snapshotsUrl) + try { + const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full` + const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot` + const repositoriesResp = await axios.get(repositoriesUrl) + const snapshotsResp = await axios.get(snapshotsUrl) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/name`, - value: repositoriesResp.data?.spec.encryptionSecret.name, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/encryptionSecret/namespace`, - value: repositoriesResp.data?.spec.encryptionSecret.namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/name`, - value: `${refDBName}-full`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/fullDBRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/name`, - value: `${refDBName}-manifest`, - force: true, - }) - commit('wizard/model$update', { - path: `/spec/init/archiver/manifestRepository/namespace`, - value: `${refNamespace}`, - force: true, - }) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/name`, + value: repositoriesResp.data?.spec.encryptionSecret.name, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/encryptionSecret/namespace`, + value: repositoriesResp.data?.spec.encryptionSecret.namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/name`, + value: `${refDBName}-full`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/fullDBRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/name`, + value: `${refDBName}-manifest`, + force: true, + }) + commit('wizard/model$update', { + path: `/spec/init/archiver/manifestRepository/namespace`, + value: `${refNamespace}`, + force: true, + }) - const resp = getComponentLogStats(snapshotsResp.data) + const resp = getComponentLogStats(snapshotsResp.data) - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: convertToLocal(resp?.end), - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: convertToLocal(resp?.start), - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: convertToLocal(resp?.end), - force: true, - }) - } catch (e) { - commit('wizard/model$update', { - path: `/spec/init/archiver/recoveryTimestamp`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/minDate`, - value: '', - force: true, - }) - commit('wizard/model$update', { - path: `/maxDate`, - value: '', - force: true, - }) - console.log(e) + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: convertToLocal(resp?.end), + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: convertToLocal(resp?.start), + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: convertToLocal(resp?.end), + force: true, + }) + } catch (e) { + commit('wizard/model$update', { + path: `/spec/init/archiver/recoveryTimestamp`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/minDate`, + value: '', + force: true, + }) + commit('wizard/model$update', { + path: `/maxDate`, + value: '', + force: true, + }) + console.log(e) + } } -} - -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -async function getAppBindings({ commit, axios, storeGet, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getAppBindings() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, + const queryParams = { + filter: { + items: { + metadata: { name: null, namespace: null }, + spec: { type: null }, + }, }, - }, + } + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + { + params: queryParams, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + const fileredResources = resources + .filter((item) => item.spec?.type === 'kubedb.com/postgres') + .map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const namespace = (item.metadata && item.metadata.namespace) || '' + return { + text: `${namespace}/${name}`, + value: { name, namespace }, + } + }) + return fileredResources + } catch (e) { + console.log(e) + return [] + } } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - { - params: queryParams, - }, - ) - const resources = (resp && resp.data && resp.data.items) || [] - - const fileredResources = resources - .filter((item) => item.spec?.type === 'kubedb.com/postgres') - .map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const namespace = (item.metadata && item.metadata.namespace) || '' - return { - text: `${namespace}/${name}`, - value: { name, namespace }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + setPointInTimeRecovery, + getRecoveryNames, + fetchNamespaces, + showRecovery, + initBundle, + returnFalse, + EqualToDatabaseMode, + onAuthChange, + clearConfiguration, + clearArbiterHidden, + isMachineNotCustom, + isMachineCustom, + getAdminOptions, + isToggleOn, + showAlerts, + onBackupSwitch, + getNodeTopology, + filterNodeTopology, + showIssuer, + setMonitoring, + updateAlertValue, + getNamespaces, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + notEqualToDatabaseMode, + showStorageSizeField, + returnFalse, + isEqualToModelPathValue, + showAuthSecretField, + getResources, + showHidden, + notEqualToDatabaseMode, + showArbiter, + notEqualToDatabaseMode, + isConfigDatabaseOn, + getPostgresVersions, + onCreateAuthSecretChange, + getSecrets, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + setBackup, + showAdditionalSettings, + getDefault, + onArchiverChange, + showArchiverAlert, + showArchiver, + getAppBindings, } } - -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - setPointInTimeRecovery, - getRecoveryNames, - fetchNamespaces, - showRecovery, - initBundle, - returnFalse, - EqualToDatabaseMode, - onAuthChange, - clearConfiguration, - clearArbiterHidden, - isMachineNotCustom, - isMachineCustom, - getAdminOptions, - isToggleOn, - showAlerts, - onBackupSwitch, - getNodeTopology, - filterNodeTopology, - showIssuer, - setMonitoring, - updateAlertValue, - getNamespaces, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - notEqualToDatabaseMode, - showStorageSizeField, - returnFalse, - isEqualToModelPathValue, - showAuthSecretField, - getResources, - showHidden, - notEqualToDatabaseMode, - showArbiter, - notEqualToDatabaseMode, - isConfigDatabaseOn, - getPostgresVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - setBackup, - showAdditionalSettings, - getDefault, - onArchiverChange, - showArchiverAlert, - showArchiver, - getAppBindings, -} diff --git a/charts/kubedbcom-postgres-editor/ui/edit-ui.yaml b/charts/kubedbcom-postgres-editor/ui/edit-ui.yaml index 148efedeb5..7aa1a6b909 100644 --- a/charts/kubedbcom-postgres-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-postgres-editor/ui/edit-ui.yaml @@ -1,1375 +1,692 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - fetch: getResources|core|v1|namespaces - label: - text: labels.namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - disableUnselect: true - disabled: true - fetch: getPostgresVersions|catalog.kubedb.com|v1alpha1|postgresversions - label: - text: labels.database.version - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/version - type: select - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/deletionPolicy - type: radio - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/authSecret/properties/name - type: input - - fetch: getClientAuthModes - label: - text: labels.client_auth_mode - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/clientAuthMode - type: radio - type: single-step-form - id: basic - title: steps.0.label -- form: - elements: - - alias: reusable_alert - chart: - name: uibytebuildersdev-component-alert - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/form/properties/alert - type: reusable-element - type: single-step-form - id: alert - title: labels.alert -- form: - discriminator: - activeDatabaseMode: - default: Standalone - type: string +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - if: isEqualToDatabaseMode|Cluster - label: - text: labels.to_update_replicas - type: label-element - - customClass: mb-20 - if: isEqualToDatabaseMode|Cluster - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/postgresopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=HorizontalScaling - - computed: setDatabaseMode - disabled: true - hasDescription: true - label: - text: labels.database.mode - onChange: deleteDatabaseModePath + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - description: options.database.mode.Standalone.description - text: options.database.mode.Standalone.label - value: Standalone - - description: options.database.mode.Cluster.description - text: options.database.mode.Cluster.label - value: Cluster - schema: - $ref: discriminator#/activeDatabaseMode - type: radio - - disabled: true - if: isEqualToDatabaseMode|Cluster - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/replicas - type: input - - disabled: true - elements: - - fetch: getStorageClassNames - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/storage/properties/storageClassName - type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/storage/properties/resources/properties/requests/properties/storage - type: input - type: single-step-form - - disabled: true - elements: - - label: - text: labels.standbyMode - options: - - text: options.standbyMode.hot - value: Hot - - text: options.standbyMode.warm - value: Warm - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/standbyMode - type: radio - - elements: - - customClass: mt-10 - label: - text: labels.electionTick - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/leaderElection/properties/electionTick - type: input - - label: - text: labels.heartbeatTick - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/leaderElection/properties/heartbeatTick - type: input - - label: - text: labels.maximumLagBeforeFailover - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/leaderElection/properties/maximumLagBeforeFailover - type: input - - label: - text: labels.period - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/leaderElection/properties/period - type: input - hideForm: true - label: - text: labels.leaderElection - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/leaderElection - show_label: true - type: single-step-form - if: isEqualToDatabaseMode|Cluster - type: single-step-form - type: single-step-form - id: topology - title: steps.1.label -- form: - discriminator: - configureTLS: - default: true - type: boolean - elements: - - label: - text: labels.to_update_tls - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/postgresopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=ReconfigureTLS - - computed: isValueExistInModel|/resources/kubedbComPostgres/spec/tls - disabled: true - label: - text: labels.enable_tls - onChange: onTlsConfigureChange - schema: - $ref: discriminator#/configureTLS - type: switch - - disabled: true + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - computed: setSSLMode - label: - text: labels.ssl_mode - options: - - text: allow - value: allow - - text: prefer - value: prefer - - text: require - value: require - - text: verify-ca - value: verify-ca - - text: verify-full - value: verify-full - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/sslMode - type: select - - elements: - - computed: setApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - title: steps.2.label -- form: + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig + elements: + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - disabled: disableInitializationSection - discriminator: - prePopulateDatabase: - type: string - elements: - - computed: initPrePopulateDatabase - label: - text: labels.prePopulateDatabase - onChange: onPrePopulateDatabaseChange + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getPostgresDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/prePopulateDatabase - type: radio - - discriminator: - dataSource: - type: string + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - computed: initDataSource - label: - text: labels.dataSource - onChange: onDataSourceChange - options: - - text: options.dataSource.script.text - value: script - - text: options.dataSource.stashBackup.text - value: stashBackup - schema: - $ref: discriminator#/properties/dataSource - type: select - - discriminator: - sourceVolumeType: - type: string - elements: - - label: - text: labels.script.path - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/init/properties/script/properties/scriptPath - type: input - - label: - text: labels.script.volume - type: label-element - - computed: initVolumeType - label: - text: labels.script.volumeType - onChange: onVolumeTypeChange - options: - - text: options.scriptSourceVolumeType.configMap.text - value: configMap - - text: options.scriptSourceVolumeType.secret.text - value: secret - schema: - $ref: discriminator#/properties/sourceVolumeType - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|configmaps - if: showConfigMapOrSecretName|configMap - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/init/properties/script/properties/configMap/properties/name - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|secrets - if: showConfigMapOrSecretName|secret - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/init/properties/script/properties/secret/properties/secretName - type: select - if: showScriptOrStashForm|script - type: single-step-form - - elements: - - label: - text: labels.restoreSession.snapshot - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/rules/properties/0/properties/snapshots/properties/0 - type: input - - discriminator: - repositoryChoise: - type: string + # postgres mode + - type: block-layout + label: Postgres + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres elements: - - label: - text: labels.repositories.title - type: label-element - - computed: setInitialRestoreSessionRepo - onChange: onInitRepositoryChoiseChange - options: - - text: options.createOrSelect.select.text - value: select - - text: options.createOrSelect.create.text - value: create - schema: - $ref: discriminator#/properties/repositoryChoise - type: radio - - allowUserDefinedOption: true - fetch: resourceNames|stash.appscode.com|v1alpha1|repositories - if: showRepositorySelectOrCreate|select - label: - text: labels.repositories.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/repository/properties/name - type: select - - alias: repository_create_init - chart: - name: uibytebuildersdev-component-repository-create - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRepositorySelectOrCreate|create - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRepository_init_repo/properties/spec/properties/backend - type: reusable-element - type: single-step-form - - if: returnFalse - label: - text: labels.backupConfiguration.targetReference.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/target/properties/ref/properties/name - type: input - - discriminator: - customizeRestoreJobRuntimeSettings: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComPostgresAutoscaler/spec/compute/postgres/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|postgres + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|postgres + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|postgres + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/controlledResources + - type: select + label: Container Controlled Values + options: + - text: Requests And Limits + value: RequestsAndLimits + - text: Requests Only + value: RequestsOnly + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/containerControlledValues + - type: block-layout + label: In Memory Storage + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/inMemoryStorage + elements: + - type: threshold-input + label: Scaling Factor Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/inMemoryStorage/properties/scalingFactorPercentage + - type: threshold-input + label: Usage Threshold Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/inMemoryStorage/properties/usageThresholdPercentage + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/nodeTopology elements: - - computed: initCustomizeRestoreJobRuntimeSettings - label: - isSubsection: true - text: labels.runtimeSettings.choise - onChange: onCustomizeRestoreJobRuntimeSettingsChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/customizeRestoreJobRuntimeSettings - type: radio - - alias: runtime_settings_init - chart: - name: uibytebuildersdev-component-runtime-settings - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRuntimeForm|yes - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/runtimeSettings - type: reusable-element - type: single-step-form - if: showScriptOrStashForm|stashBackup - type: single-step-form - - if: returnFalse - label: - text: labels.waitForInitialRestore - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/init/properties/waitForInitialRestore - type: switch - if: showInitializationForm - type: single-step-form - type: single-step-form - type: single-step-form - id: initialization - title: steps.3.label -- form: - discriminator: - repoInitialSelectionStatus: - type: string - scheduleBackup: - default: "yes" - type: string - elements: - - computed: initScheduleBackupForEdit - if: showScheduleBackup - label: - text: labels.backup.title - onChange: onScheduleBackupChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/scheduleBackup - type: radio - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean - elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string - elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean - elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean - elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - if: showBackupForm - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.4.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComPostgres/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean + - type: block-layout + showLabels: false elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComPostgres/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: Postgres + showLabels: true elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPostgres/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPostgres/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - elements: - - elements: - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - type: single-step-form - id: pod-template - title: steps.6.label -- form: - elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.7.label -- form: - elements: - - elements: - - discriminator: - configuration: - type: string - configurationSource: - default: use-existing-config - type: string - elements: - - label: - text: labels.to_update_config - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/postgresopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=Reconfigure - - disabled: true - label: - text: labels.custom_config - onChange: onConfigurationSourceChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/configurationSource - type: radio - - allowUserDefinedOption: true - disabled: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSource - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComPostgres/properties/spec/properties/configSecret/properties/name - type: select - type: single-step-form - type: single-step-form - type: single-step-form - id: custom-config - title: steps.8.label -- form: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComPostgresAutoscaler/spec/storage/postgres/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/usageThreshold + - type: input + label: Scaling Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/scalingThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComPostgres/spec/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComPostgresAutoscaler/spec/storage/postgres/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComPostgresAutoscaler/spec/storage/postgres/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: Select Namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getPostgresDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComPostgres/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComPostgresAutoscaler/spec/compute/postgres/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string - elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|postgres - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|postgres - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|postgres - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/controlledResources - type: multiselect - - label: - text: Container Controlled Values - options: - - RequestsAndLimits - - RequestsOnly - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/containerControlledValues - type: select - - elements: - - label: - text: ScalingFactor Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/inMemoryStorage/properties/scalingFactorPercentage - type: input - - label: - text: Usage Threshold Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/inMemoryStorage/properties/usageThresholdPercentage - type: input - label: - text: In Memory Storage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres/properties/inMemoryStorage - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres - type: single-step-form - label: - text: Postgres - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: OpsRequest Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.9.label -- form: - elements: - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: Select Namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getPostgresDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComPostgresAutoscaler/spec/storage/postgres/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/trigger - type: select - - label: - text: Expansion Mode + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/usageThreshold - type: input - - label: - text: Scaling Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/scalingThreshold - type: input - - addFormLabel: Scaling Rules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComPostgres/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPostgres/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComPostgresAutoscaler/spec/storage/postgres/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComPostgresAutoscaler/spec/storage/postgres/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/storage/properties/postgres/properties/upperBound - type: input - label: - text: Postgres - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/compute/properties/postgres - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: OpsRequest Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComPostgresAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.10.label -- form: - discriminator: - binding: - default: false - type: boolean + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComPostgres/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: + type: input + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComPostgres/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: binding + label: Gateway Binding elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -type: multi-step-form + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-postgres-editor/ui/functions.js b/charts/kubedbcom-postgres-editor/ui/functions.js index 2b184023c9..8567f0094e 100644 --- a/charts/kubedbcom-postgres-editor/ui/functions.js +++ b/charts/kubedbcom-postgres-editor/ui/functions.js @@ -1,2821 +1,1463 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', true) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + /****** Backup Configuration *********/ + + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, ) - const resources = (resp && resp.data && resp.data.items) || [] + initRepositoryChoiseForEdit() - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + function initScheduleBackup() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } - return ans -} + function onScheduleBackupChange() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (scheduleBackup === 'no') { + // delete stashAppscodeComBackupConfiguration + commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + // delete annotation from kubedbComPostgres annotation + deleteKubeDbComPostgresDbAnnotation() + } else { + const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + // create stashAppscodeComBackupConfiguration and initialize it if not exists - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const dbName = getValue(model, '/metadata/release/name') - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + if ( + !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && + !isBluePrint + ) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration', + value: stashAppscodeComBackupConfiguration, + }) + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + } + } } - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + function getBackupConfigsAndAnnotations(getValue, model) { + const stashAppscodeComBackupConfiguration = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration', + ) + const kubedbComPostgresAnnotations = + getValue(model, '/resources/kubedbComPostgres/metadata/annotations') || {} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + const isBluePrint = Object.keys(kubedbComPostgresAnnotations).some( + (k) => + k === 'stash.appscode.com/backup-blueprint' || + k === 'stash.appscode.com/schedule' || + k.startsWith('params.stash.appscode.com/'), + ) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' return { - text: name, - value: name, + stashAppscodeComBackupConfiguration, + isBluePrint, } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} - -// ************************* Basic Info ********************************************** -async function getPostgresVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true + function deleteKubeDbComPostgresDbAnnotation() { + const annotations = getValue(model, '/resources/kubedbComPostgres/metadata/annotations') || {} + const filteredKeyList = + Object.keys(annotations).filter( + (k) => + k !== 'stash.appscode.com/backup-blueprint' && + k !== 'stash.appscode.com/schedule' && + !k.startsWith('params.stash.appscode.com/'), + ) || [] + const filteredAnnotations = {} + filteredKeyList.forEach((k) => { + filteredAnnotations[k] = annotations[k] }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] - } -} - -// ************************* Auth Secret Field ****************************************** -function showAuthPasswordField({ model, getValue, watchDependency }) { - watchDependency('model#/resources') - const modelPathValue = getValue(model, '/resources') - return !!( - modelPathValue && - modelPathValue.secret && - modelPathValue.secret.metadata && - modelPathValue.secret.metadata.name && - !showAuthSecretField({ model, getValue, watchDependency }) - ) -} - -function showAuthSecretField({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComPostgres/spec') - const modelPathValue = getValue(model, '/resources/kubedbComPostgres/spec') - return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) -} - -function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { - const resp = - !showAuthSecretField({ model, getValue, watchDependency }) && - !showAuthPasswordField({ model, getValue, watchDependency }) - const secret = getValue(model, '/resources/secret_auth') - if (resp && !secret) { commit('wizard/model$update', { - path: '/resources/secret_auth', - value: { - data: { - password: '', - }, - }, - force: true, + path: '/resources/kubedbComPostgres/metadata/annotations', + value: filteredAnnotations, }) } - return resp -} -function getClientAuthModes({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComPostgres/spec/version') + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false + } - const version = getValue(model, '/resources/kubedbComPostgres/spec/version') - // major version section from version - const major = parseInt(version && version.split('.')[0]) + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let namespaceList = [] + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComPostgres') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - const options = ['md5', 'cert'] + // get values.yaml to populate data when backup-config is being created + try { + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version - if (major >= 11) { - options.push('scram') - } + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - return options.map((item) => ({ text: item, value: item })) -} + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` -function onVersionChange({ model, getValue, commit }) { - const version = getValue(model, '/resources/kubedbComPostgres/spec/version') - const major = parseInt(version && version.split('.')[0]) - const defaultValue = major >= 11 ? 'scram' : 'md5' + const resp = await axios.get(url) - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/clientAuthMode', - value: defaultValue, - force: true, - }) -} + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} + } catch (e) { + console.log(e) + } -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/resources/kubedbComPostgres/spec/replicas') - watchDependency('model#/resources/kubedbComPostgres/spec/replicas') + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } + } - if (modelPathValue > 1) { - return 'Cluster' - } else { - return 'Standalone' - } -} + // check config with metadata name first + let config = configs?.find( + (item) => + item.metadata?.name === name && + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) -let storageClassList = [] -async function getStorageClassNames({ axios, storeGet, commit, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) + // set backup switch here + isBackupOn = !!config - const resources = (resp && resp.data && resp.data.items) || [] + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends - storageClassList = resources - const initialStorageClass = getValue( - model, - '/resources/kubedbComPostgres/spec/storage/storageClassName', - ) - if (!initialStorageClass) setStorageClass({ model, getValue, commit }) - return resources -} + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` -function setStorageClass({ model, getValue, commit }) { - const deletionPolicy = getValue(model, '/resources/kubedbComPostgres/spec/deletionPolicy') || '' - let storageClass = - getValue(model, '/resources/kubedbComPostgres/spec/storage/storageClassName') || '' - const suffix = '-retain' + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions + } - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + setDiscriminatorValue('isBackupDataLoaded', true) + } - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') + } - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + function setBackupType() { + return 'BackupConfig' + } + + function getTypes() { + const arr = [ + { + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', + }, + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] + + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) } + return arr } - if (storageClass) { + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/storage/storageClassName', - value: storageClass, + path: '/backupType', + value: type, force: true, }) - } -} - -function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - if (mode === 'Cluster') { - replicas = getValue(model, '/resources/kubedbComPostgres/spec/replicas') - if (!replicas) { + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/replicas', - value: 3, + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), force: true, }) } - } else if (mode === 'Standalone') { - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/standbyMode') - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/leaderElectiion') + commit('wizard/model$delete', '/context') + commit('wizard/model$update', { + path: '/resources/kubedbComPostgres', + value: objectCopy(dbResource), + force: true, + }) } -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} - -// ************************** TLS ******************************88 - -function setApiGroup() { - return 'cert-manager.io' -} -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComPostgres/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComPostgres/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComPostgres/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComPostgres/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + return selectedType === type } - if (!url) return [] + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations - try { - const resp = await axios.get(url) + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) + } - const resources = (resp && resp.data && resp.data.items) || [] + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') + if (blueprintSwitch) addLabelAnnotation('annotations') + else deleteLabelAnnotation('annotations') + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComPostgres/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) + } else { + commit('wizard/model$delete', path) + } + } - return !!(resp && resp.length) -} + function addLabelAnnotation(type) { + const obj = objectCopy(initialDbMetadata[type]) -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` + } else { + obj['kubedb.com/archiver'] = 'true' + } - return !resp -} + commit('wizard/model$update', { + path: `/resources/kubedbComPostgres/metadata/${type}`, + value: obj, + force: true, + }) + } -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComPostgres/spec/sslMode') - return val || 'require' -} + function deleteLabelAnnotation(type) { + const obj = initialDbMetadata[type] -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/tls', - value: { issuerRef: {}, certificates: [] }, + path: `/resources/kubedbComPostgres/metadata/${type}`, + value: obj, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/sslMode') } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/monitor', - value: {}, + path: '/context', + value: context, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/monitor') + if (context === 'Create') { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, + force: true, + }) + } + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) } - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) + const list = filteredList?.map((ele) => ele.metadata.name) + return list + } -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/monitor/prometheus/exporter', - value: {}, + path: '/resources/coreKubestashComBackupConfiguration', + value: configDetails, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/monitor/prometheus/exporter') } -} -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' + } -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' + } -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComPostgres/spec/init/initialized') - watchDependency('model#/resources/kubedbComPostgres/spec/init/initialized') - return !!initialized -} + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName + } -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComPostgres/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComPostgres/spec/init/script') + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' + } - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { + return repoInitialSelectionStatus + } + + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, + path: modelPath, + value: session, }) + } + } + + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComPostgres/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'PostgresBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } + if (value) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, + path: '/resources/catalogAppscodeComPostgresBinding', + value: bindingValues, force: true, }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComPostgresBinding') } } -} -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComPostgres/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComPostgresBinding') + return isExposeBinding + } - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) + /****** Compute Autoscaller *********/ - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') + let autoscaleType = '' + let dbDetails = {} - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComPostgres/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/init/script') + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name') || + '' - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/postgreses/${name}`, + ) + dbDetails = resp.data || {} - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } } - } -} -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComPostgres/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComPostgres/spec/init/script/secret/secretName') + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComPostgresAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, + }) + } - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} + function isKubedb() { + return !!storeGet('/route/params/actions') + } -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/init/script/secret') + function isConsole() { + const isKube = isKubedb() - if (!valueExists(model, getValue, '/resources/kubedbComPostgres/spec/init/script/configMap')) { + if (isKube) { + const dbName = storeGet('/route/params/name') || '' commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/init/script/configMap', - value: { - name: '', - }, + path: '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComPostgres/spec/init/script/secret')) { + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/init/script/secret', - value: { - secretName: '', - }, + path: '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/name', + value: modifiedName, + force: true, }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} + return !isKube + } -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - return repositoryChoise === value -} + const resources = (resp && resp.data && resp.data.items) || [] -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } }) + } - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } -} -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComPostgres/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} + async function getPostgresDbs() { + // watchDependency('model#/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/postgreses`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } + + const resources = (resp && resp.data && resp.data.items) || [] + + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } -} -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name') || + '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, + path: '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/name', + value: modifiedName, force: true, }) - } - } -} -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + // delete the other type object from vuex wizard model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPostgresAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute', + ) + } - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) + async function fetchTopologyMachines() { + const instance = hasAnnotations() - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration + } -// schedule bakcup + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComPostgresAnnotations = - getValue(model, '/resources/kubedbComPostgres/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComPostgresAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] - return { - stashAppscodeComBackupConfiguration, - isBluePrint, + return !!instance } -} - -function deleteKubeDbComPostgresDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComPostgres/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/metadata/annotations', - value: filteredAnnotations, - }) -} -function addKubeDbComPostgresDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComPostgres/metadata/annotations') || {} + function setAllowedMachine(minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value + if (minmax === 'min') return mn + else return mx } - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/metadata/annotations', - value: annotations, - force: true, - }) -} + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') + return dependantIndex === -1 ? machines : filteredMachine + } - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComPostgres annotation - deleteKubeDbComPostgresDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] - // create stashAppscodeComBackupConfiguration and initialize it if not exists + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine - const dbName = getValue(model, '/metadata/release/name') + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute/${type}` - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, }) commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: { ...annotations }, force: true, }) } } -} -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') + function hasNoAnnotations() { + return !hasAnnotations() + } - if (scheduleBackup === 'yes') return true - else return false -} + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, + }) + return list + } -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -async function initBackupData({ commit, storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComPostgres') - initialDbMetadata = objectCopy(dbResource.metadata) - initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check storageclass archiver annotation - if (initialArchiver) { - isArchiverAvailable = true - } else { - const storageClassName = dbResource?.spec?.storage?.storageClassName - const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` try { const resp = await axios.get(url) - const archAnnotation = resp.data?.metadata?.annotations - const annotationKeyToFind = `${resource}.${group}/archiver` - if (archAnnotation[annotationKeyToFind]) { - isArchiverAvailable = true - archiverObjectToCommit = { - ref: { - name: archAnnotation[annotationKeyToFind], - namespace: 'kubedb', - }, - } - } + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList } catch (e) { console.log(e) } + return [] } - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') ) + } - // set backup switch here - isBackupOn = !!config - - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends - - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` - - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions + function setApplyToIfReady() { + return 'IfReady' } - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value } - setDiscriminatorValue('isBackupDataLoaded', true) -} + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -async function setBackupType() { - return 'BackupConfig' -} + const resources = (resp && resp.data && resp.data.items) || [] -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - - if (dbResource?.spec?.replicas !== 1 && isArchiverAvailable) { - arr.push({ - description: 'Enable/Disable Archiver', - text: 'Archiver', - value: 'Archiver', - }) + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } } - return arr -} -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), - force: true, - }) - } - commit('wizard/model$delete', '/context') + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres', - value: objectCopy(dbResource), - force: true, - }) -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - return selectedType === type -} + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations + return ans + } - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} + /****** Monitoring *********/ -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComPostgres/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/monitor') + } -function onArchiverChange({ getValue, discriminator, commit, model, storeGet }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComPostgres/spec/archiver' - if (archiverSwitch) { + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', + force: true, }) - } else { - commit('wizard/model$delete', path) } -} - -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus } - commit('wizard/model$update', { - path: `/resources/kubedbComPostgres/metadata/${type}`, - value: obj, - force: true, - }) -} + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComPostgres/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/monitor/prometheus/exporter') + } + } -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] + function isValueExistInModel(path) { + const modelValue = getValue(model, path) + return !!modelValue + } - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value + } - commit('wizard/model$update', { - path: `/resources/kubedbComPostgres/metadata/${type}`, - value: obj, - force: true, - }) -} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComPostgres/spec/metadata/labels') -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} + const agent = getValue(model, '/resources/kubedbComPostgres/spec/monitor/agent') -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, - force: true, - }) + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) + } } -} -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComPostgres/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } + } - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} + const secrets = (resp && resp.data && resp.data.items) || [] -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function getNamespaceArray() { - return namespaceList -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } + } -// invoker form -function initBackupInvoker() { - return 'backupConfiguration' -} + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` -function onBackupInvokerChange({ getValue, discriminator, commit, model, storeGet }) { - const kind = storeGet('/resource/layout/result/resource/kind') - const backupInvoker = getValue(discriminator, '/backupInvoker') - const annotations = getValue(model, '/resources/kubedbComPostgres/metadata/annotations') + const isKube = !!storeGet('/route/params/actions') - // get name namespace labels to set in db resource when backup is not enabled initially - - if (backupInvoker === 'backupConfiguration') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: initialModel, - force: true, - }) - - if ( - !dbResource.metadata?.annotations?.['blueprint.kubestash.com/name'] && - !dbResource.metadata?.annotations?.['blueprint.kubestash.com/namespace'] - ) { - delete annotations['blueprint.kubestash.com/name'] - delete annotations['blueprint.kubestash.com/namespace'] - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/metadata/annotations', - value: annotations, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - if (!isBackupOn) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } - annotations['blueprint.kubestash.com/name'] = `${kind.toLowerCase()}-blueprint` - annotations['blueprint.kubestash.com/namespace'] = 'kubedb' - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/metadata/annotations', - value: annotations, - force: true, - }) + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/postgresopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name', + ) } } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComPostgres/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComPostgresDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComPostgresDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComPostgres/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComPostgres/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) } -} -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComPostgres/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComPostgres/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComPostgres/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComPostgres/spec/metadata/labels') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComPostgres/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComPostgres/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'postgres'), - force: true, + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') } -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComPostgres/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', ) - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] - } -} - -//////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// - -//////////////////// service monitor /////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/user.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComPostgres/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} + console.log({ configMapName }) -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/user.conf') -} - -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/user.conf') - return atob(value) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComPostgres/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - } -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/postgresopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} - -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} + if (!configMapName) return [] -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} - -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) - } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` + const configMaps = (resp && resp.data && resp.data.data) || {} - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data - } - } catch (e) { - console.log(e) - } - return [] -} - -function initBlueprint() { - return 'create' -} -function initUsagePolicy() { - return 'Same' -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function setInitSchedule({ getValue, commit, model }, modelPath, value) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} - -//////////////////// Auto scaler ///////////////// -let autoscaleType = '' -let dbDetails = {} - -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) - - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace', - value: namespace, - force: true, - }) + return configMapKeys + } catch (e) { + console.log(e) + return [] } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComPostgres/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -async function getDbDetails({ axios, storeGet, getValue, model, setDiscriminatorValue, commit }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name') || - '' + if (!secretName) return [] - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/postgreses/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) + const secret = (resp && resp.data && resp.data.data) || {} + + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) + + return secretKeys } catch (e) { console.log(e) + return [] } } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComPostgresAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo( - { watchDependency, getValue, commit, discriminator }, - mongoType, - type, -) { - watchDependency('discriminator#/dbDetails') - autoscaleType = type - const dbDetailsSuccess = getValue(discriminator, '/dbDetails') - - if (!dbDetailsSuccess) return false - - const { spec } = dbDetails || {} - const { shardTopology, replicaSet } = spec || {} - let verd = '' - if (shardTopology) verd = 'sharded' - else { - if (replicaSet) verd = 'replicaSet' - else verd = 'standalone' - } - clearSpecModel({ commit }, verd) - return mongoType === verd -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getPostgresDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/postgreses`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from vuex wizard model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComPostgresAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name', - ) + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComPostgresBinding') + return isExposeBinding } -} - -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComPostgresAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} - -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) - } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} -function setApplyToIfReady() { - return 'IfReady' -} - -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComPostgres/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'PostgresBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, } - } else { - if (!isNaN(value)) { - value += 'Gi' + + if (value) { commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, + path: '/resources/catalogAppscodeComPostgresBinding', + value: bindingValues, force: true, }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComPostgresBinding') } } -} -function objectCopy(obj) { - const temp = JSON.stringify(obj) - return JSON.parse(temp) -} - -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComPostgresBinding') - 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 labels = getValue(model, '/resources/kubedbComPostgres/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'PostgresBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { - name: dbName, - namespace: dbNamespace, - }, - }, - } - - if (value) { - await commit('wizard/model$update', { - path: '/resources/catalogAppscodeComPostgresBinding', - value: bindingValues, - force: true, - }) - } else { - await commit('wizard/model$delete', '/resources/catalogAppscodeComPostgresBinding') + function returnFalse() { + return false } -} -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) - - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) - - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } } } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComPostgresAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComPostgresAutoscaler/spec/compute/${type}` - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + return { + initScheduleBackup, + initScheduleBackupForEdit, + onScheduleBackupChange, + deleteKubeDbComPostgresDbAnnotation, + getBackupConfigsAndAnnotations, + showBackupForm, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + onBackupTypeChange, + isBackupType, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showConfigList, + showSchedule, + showScheduleBackup, + getDefaultSchedule, + initRepositoryChoiseForEdit, + addLabelAnnotation, + deleteLabelAnnotation, + onInputChangeSchedule, + objectCopy, + valueExists, + + getDbDetails, + isKubedb, + isConsole, + getNamespaces, + isRancherManaged, + onNamespaceChange, + getPostgresDbs, + initMetadata, + fetchTopologyMachines, + setTrigger, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + setControlledResources, + fetchNodeTopology, + isNodeTopologySelected, + showOpsRequestOptions, + setApplyToIfReady, + + handleUnit, + + getOpsRequestUrl, + isValueExistInModel, + setValueFromDbDetails, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + + isBindingAlreadyOn, + addOrRemoveBinding, } } - -return { - handleUnit, - isConsole, - getNamespaces, - getPostgresDbs, - isKubedb, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - getPostgresVersions, - showAuthPasswordField, - showAuthSecretField, - showNewSecretCreateField, - getClientAuthModes, - onVersionChange, - setDatabaseMode, - getStorageClassNames, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComPostgresDbAnnotation, - addKubeDbComPostgresDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - getCreateNameSpaceUrl, - setStorageClass, - isBindingAlreadyOn, - addOrRemoveBinding, - - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - onBackupTypeChange, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - getNamespaceArray, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, -} diff --git a/charts/kubedbcom-proxysql-editor-options/ui/create-ui.yaml b/charts/kubedbcom-proxysql-editor-options/ui/create-ui.yaml index f1626a67c9..b38caae540 100644 --- a/charts/kubedbcom-proxysql-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-proxysql-editor-options/ui/create-ui.yaml @@ -1,306 +1,282 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/ProxySQL/versions - if: isToggleOn|databases/ProxySQL/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/ProxySQL/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/ProxySQL/versions + if: + type: function + name: isToggleOn|databases/ProxySQL/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/ProxySQL/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/ProxySQL/mode + loader: getAdminOptions|databases/ProxySQL/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/ProxySQL/mode + label: Database Mode + watcher: + func: clearArbiterHidden + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: EqualToDatabaseMode|Replicaset + label: Replicas + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/ProxySQL/mode - fetch: getAdminOptions|databases/ProxySQL/mode - hasDescription: true - if: isToggleOn|databases/ProxySQL/mode - label: - text: labels.database.mode - onChange: clearArbiterHidden - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: EqualToDatabaseMode|Replicaset - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine Profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage Class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Backend Section + type: label-element + - loader: getAppBindings + label: Backend + refresh: true + schema: schema/properties/spec/properties/backend + type: select + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotation + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - label: Sync Users? + schema: schema/properties/spec/properties/syncUsers + type: switch + - if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + options: + - description: Postgres sharded cluster for high performance and high availability. + text: Shared + value: Shared + - description: For production applications with sophisticated workload requirements. + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default type: select - - label: - text: labels.backend_section - type: label-element - - fetch: getAppBindings - label: - text: labels.backend + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology refresh: true - schema: - $ref: schema#/properties/spec/properties/backend + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default type: select - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotation - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - label: - text: labels.sync_users_question - schema: - $ref: schema#/properties/spec/properties/syncUsers + label: Advanced Configuration + showLabels: true + hideBlock: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - refresh: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - elements: + - label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default + type: switch + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - elements: - - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - if: isToggleOn|tls - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|tls + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-proxysql-editor-options/ui/functions.js b/charts/kubedbcom-proxysql-editor-options/ui/functions.js index 1f1eab5342..8b7b3410fe 100644 --- a/charts/kubedbcom-proxysql-editor-options/ui/functions.js +++ b/charts/kubedbcom-proxysql-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,93 +317,61 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, ) - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} - -async function getProxysqlVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('monitoring', false) - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resources = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - // keep only non deprecated versions - const filteredProxysqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const resources = (resp && resp.data && resp.data.items) || [] - filteredProxysqlVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredProxysqlVersions -} + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } -async function getAppBindings({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getProxysqlVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { type: null }, + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, }, - }, - } + } - try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, { params: queryParams, }, @@ -409,960 +379,962 @@ async function getAppBindings({ axios, storeGet }) { const resources = (resp && resp.data && resp.data.items) || [] - const fileredResources = resources - .filter((item) => item.spec?.type === 'kubedb.com/mysql') - .map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] - } -} + // keep only non deprecated versions + const filteredProxysqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + filteredProxysqlVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredProxysqlVersions } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + async function getAppBindings() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { type: null }, + }, }, - }, - ) + } - const secrets = (resp && resp.data && resp.data.items) || [] + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + { + params: queryParams, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + const fileredResources = resources + .filter((item) => item.spec?.type === 'kubedb.com/mysql') + .map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + return fileredResources + } catch (e) { + console.log(e) + return [] + } + } - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + const secrets = (resp && resp.data && resp.data.items) || [] + + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) - } else { - array = machineList - .map((machine) => { + + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: comparePath, - value: memory, + path: commitPath, + value: val, force: true, }) - return memory - } else { + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + if (val === 'capz' && ifDedicated()) return true } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} - -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} - -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) - } - return [] -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} - -function setStorageClass({ model, getValue, commit, watchDependency, discriminator }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + return [] } - const isChangeable = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } -} - -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} - -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') - - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') - } -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/ProxySQL/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/ProxySQL/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/ProxySQL/mode/available') || [] - if (arr.length) defMode = arr[0] - } + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } + + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - if (!features.includes('tls')) { + function clearArbiterHidden() { commit('wizard/model$update', { - path: '/spec/admin/tls/default', + path: `/spec/arbiter/enabled`, value: false, force: true, }) - } - if (!features.includes('binding')) { + commit('wizard/model$update', { - path: '/spec/admin/expose/default', + path: `/spec/hidden/enabled`, value: false, force: true, }) } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) + + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode } - setDiscriminatorValue('/bundleApiLoaded', true) -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } + + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } + + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } + commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!getValue(model, `/spec/admin/databases/ProxySQL/mode/toggle`)) { + let defMode = getDefault('databases/ProxySQL/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/ProxySQL/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + setDiscriminatorValue('/bundleApiLoaded', true) } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function returnFalse() { + return false + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function EqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue === mode -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function EqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue === mode + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - EqualToDatabaseMode, - getNamespaces, - updateAlertValue, - setStorageClass, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - returnFalse, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - getResources, - getProxysqlVersions, - getAppBindings, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setBackup, - showAdditionalSettings, - getDefault, + return { + onReferSecretChange, + showReferSecretSwitch, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + initBundle, + returnFalse, + EqualToDatabaseMode, + getNamespaces, + updateAlertValue, + setStorageClass, + getAdminOptions, + isToggleOn, + showAlerts, + getNodeTopology, + clearArbiterHidden, + showHidden, + isConfigDatabaseOn, + notEqualToDatabaseMode, + filterNodeTopology, + onAuthChange, + setMonitoring, + isMachineNotCustom, + isMachineCustom, + showIssuer, + showArbiter, + clearConfiguration, + onBackupSwitch, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + getResources, + getProxysqlVersions, + getAppBindings, + getSecrets, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setBackup, + showAdditionalSettings, + getDefault, + } } diff --git a/charts/kubedbcom-proxysql-editor/ui/edit-ui.yaml b/charts/kubedbcom-proxysql-editor/ui/edit-ui.yaml index 82e18545f4..ede329ff56 100644 --- a/charts/kubedbcom-proxysql-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-proxysql-editor/ui/edit-ui.yaml @@ -1,985 +1,444 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - label: - text: labels.namespace - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: input - - disabled: true - label: - text: labels.database.version - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/version - type: input - - disabled: true - label: - text: labels.replicas - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/replicas - type: input - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/deletionPolicy - type: radio - - label: - text: labels.backend_section - type: label-element - - disabled: true - label: - text: labels.backend - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/backend/properties/name - type: input - - label: - text: labels.sync_users_question - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/syncUsers - type: switch - - label: - text: labels.database.secret - type: label-element - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/authSecret/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - elements: - - alias: reusable_alert - chart: - name: uibytebuildersdev-component-alert - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/form/properties/alert - type: reusable-element - type: single-step-form - id: alert - title: steps.1.label -- form: - discriminator: - configureTLS: - default: true - type: boolean - elements: - - label: - text: labels.to_update_tls - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|ReconfigureTLS - - computed: isValueExistInModel|/resources/kubedbComProxySQL/spec/tls - disabled: true - label: - text: labels.enable_tls - onChange: onTlsConfigureChange - schema: - $ref: discriminator#/configureTLS - type: switch - - disabled: true - elements: - - elements: - - computed: setApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - title: steps.3.label -- form: - elements: - - alias: reusable_health_checker - chart: - name: uibytebuildersdev-component-health-checker - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/healthChecker - type: reusable-element - type: single-step-form - id: health-checker - title: steps.4.label -- form: +type: multi-step-form +step : + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - label: - text: labels.to_update_disabled_section - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|Reconfigure - - disabled: true - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.initConfig.adminVariables - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/adminVariables - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/adminVariables - type: input - - disabled: true - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.initConfig.mysqlVariables - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlVariables - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlVariables - type: input - - addFormLabel: labels.initConfig.mysqlQueryRule - computed: setMySQLRules - disabled: true - element: - discriminator: - mysqlQueryRules: - emitAs: mysqlQueryRules - type: array + - type: block-layout + if: + type: function + name: isConsole elements: - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.initConfig.rules - schema: - $ref: discriminator#/properties/mysqlQueryRules/items/properties/rules - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: discriminator#/properties/mysqlQueryRules/items/properties/rules/additionalProperties - type: input - schema: - $ref: discriminator#/properties/mysqlQueryRules/items - type: single-step-form - label: - text: labels.initConfig.mysqlQueryRules - onChange: onMySQLRulesChange - schema: - $ref: discriminator#/properties/mysqlQueryRules - tableContents: - - inTableColumn: true - label: - text: labels.initConfig.rules - path: rules - type: value - typeOfValue: key-value - type: single-step-form-array - - addFormLabel: labels.initConfig.mysqlUser - customClass: mt-20 - disabled: true - element: - elements: - - label: - text: labels.initConfig.username - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/username - type: input - - label: - text: labels.initConfig.active - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/active - type: input - - label: - text: labels.initConfig.default_schema - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/default_schema - type: input - - label: - text: labels.initConfig.use_ssl - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/use_ssl - type: input - - label: - text: labels.initConfig.attributes - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/attributes - type: input - - label: - text: labels.initConfig.backend - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/backend - type: input - - label: - text: labels.initConfig.comment - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/comment - type: input - - label: - text: labels.initConfig.default_hostgroup - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/default_hostgroup - type: input - - label: - text: labels.initConfig.fast_forward - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/fast_forward - type: input - - label: - text: labels.initConfig.frontend - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/frontend - type: input - - label: - text: labels.initConfig.max_connections - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/max_connections - type: input - - label: - text: labels.initConfig.schema_locked - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/schema_locked - type: input - - label: - text: labels.initConfig.transaction_persistent - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items/properties/transaction_persistent - type: input - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers/items - type: single-step-form - label: - text: labels.initConfig.mysqlUsers - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/initConfig/properties/mysqlUsers - tableContents: - - inTableColumn: true - label: - text: labels.initConfig.username - path: username - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.initConfig.active - path: active - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.initConfig.default_schema - path: default_schema - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.initConfig.use_ssl - path: use_ssl - type: value - typeOfValue: string - - label: - text: labels.initConfig.attributes - path: attributes - type: value - typeOfValue: string - - label: - text: labels.initConfig.backend - path: backend - type: value - typeOfValue: string - - label: - text: labels.initConfig.comment - path: comment - type: value - typeOfValue: string - - label: - text: labels.initConfig.default_hostgroup - path: default_hostgroup - type: value - typeOfValue: string - - label: - text: labels.initConfig.fast_forward - path: fast_forward - type: value - typeOfValue: string - - label: - text: labels.initConfig.frontend - path: frontend - type: value - typeOfValue: string - - label: - text: labels.initConfig.max_connections - path: max_connections - type: value - typeOfValue: string - - label: - text: labels.initConfig.schema_locked - path: schema_locked - type: value - typeOfValue: string - - label: - text: labels.initConfig.transaction_persistent - path: transaction_persistent - type: value - typeOfValue: string - type: single-step-form-array - type: single-step-form - id: init-config - title: steps.5.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComProxySQL/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComProxySQL/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComProxySQL/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComProxySQL/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - elements: - - label: - text: labels.to_update_disabled_section - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - id: pod-template - title: steps.7.label -- form: - elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.8.label -- form: - elements: - - label: - text: labels.to_update_config - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|Reconfigure - - disabled: true - discriminator: - setCustomConfig: - type: string - elements: - - computed: setCustomConfigConfigureChoice - label: - text: labels.setCustomConfig + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/setCustomConfig - type: radio - - discriminator: - configurationSource: - default: use-existing-config - type: string + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - label: - text: labels.custom_config - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/properties/configurationSource - type: radio - - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/configSecret/properties/name - type: input - if: isEqualToDiscriminatorPath|yes|/setCustomConfig - type: single-step-form - type: single-step-form - type: single-step-form - id: custom-config - title: steps.9.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + # proxysql mode + - type: block-layout + label: ProxySQL + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComProxySQLAutoscaler/spec/compute/proxysql/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|proxysql + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|proxysql + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|proxysql + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComProxySQL/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComProxySQLAutoscaler/spec/compute/proxysql/trigger - label: - text: Trigger + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComProxySQL/spec/monitor/agent elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|proxysql - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|proxysql - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|proxysql - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql/properties/controlledResources - type: multiselect - label: - text: ProxySQL - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/proxysql - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComProxySQLAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -type: multi-step-form + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComProxySQL/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComProxySQL/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: + type: input + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComProxySQL/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true \ No newline at end of file diff --git a/charts/kubedbcom-proxysql-editor/ui/functions.js b/charts/kubedbcom-proxysql-editor/ui/functions.js index 6f3acdde68..a6a882b192 100644 --- a/charts/kubedbcom-proxysql-editor/ui/functions.js +++ b/charts/kubedbcom-proxysql-editor/ui/functions.js @@ -1,1264 +1,804 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + let autoscaleType = '' + let dbDetails = {} + + function isConsole() { + const isKube = isKubedb() + + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + return !isKube } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + function isKubedb() { + return !!storeGet('/route/params/actions') } - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, }) - } - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function returnTrue() { - return true -} - -function returnFalse() { - return false -} - -function returnStringYes() { - return 'yes' -} - -// ************************* Basic Info ********************************************** -async function getProxySQLVersions({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/proxysqlversions`, - { - params: queryParams, - }, - ) const resources = (resp && resp.data && resp.data.items) || [] - // keep only non deprecated versions - const filteredDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredDbVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true + return { + text: name, + value: name, + } }) - return filteredDbVersions - } catch (e) { - console.log(e) - return [] } -} -async function getAppBindings({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { type: null }, - }, - }, - } + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const fileredResources = resources - .filter( - (item) => - item.spec?.type === 'kubedb.com/mysql' || item.spec?.type === 'kubedb.com/mariadb', - ) - .map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] - } -} - -// ************************** TLS ******************************88 - -function setApiGroup() { - return 'cert-manager.io' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComProxySQL/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComProxySQL/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComProxySQL/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComProxySQL/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } - - if (!url) return [] - - try { - const resp = await axios.get(url) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + return { + text: name, + value: name, + } }) - return resources - } catch (e) { - console.log(e) - return [] } -} -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name') || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/proxysqls/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComProxySQL/spec/tls', - value: { issuerRef: {}, certificates: [] }, + path: `/metadata/release/name`, + value: name, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComProxySQL/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComProxySQL/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComProxySQL/spec/monitor', - value: {}, + path: `/metadata/release/namespace`, + value: namespace, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComProxySQL/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComProxySQL/spec/monitor/prometheus/exporter', - value: {}, + path: `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name`, + value: name, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComProxySQL/spec/monitor/prometheus/exporter') - } -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComProxySQL/spec/monitor/agent') - if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], + path: `/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, force: true, }) } -} -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComProxySQL/spec/metadata/labels') + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name') || + '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) + + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute', + ) + } + + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] + } - const agent = getValue(model, '/resources/kubedbComProxySQL/spec/monitor/agent') + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } - if (agent === 'prometheus.io') { + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute/${type}/controlledResources` commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, + path: path, + value: list, force: true, }) + return list } -} -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } - const agent = getValue(model, '/resources/kubedbComProxySQL/spec/monitor/agent') + function setApplyToIfReady() { + return 'IfReady' + } - const labels = getValue(model, '/resources/kubedbComProxySQL/spec/metadata/labels') + async function fetchTopologyMachines() { + const instance = hasAnnotations() - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComProxySQL/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } -} -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComProxySQL/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) + function setAllowedMachine(minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + if (minmax === 'min') return mn + else return mx } -} -/************************************* Database Secret Section ********************************************/ + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComProxySQL/spec/authSecret') + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - return !authSecret -} + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + console.log(nodeGroups) -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') + return dependantIndex === -1 ? machines : filteredMachine + } - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] + + return !!instance } -} -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComProxySQL/spec/init/initialized') - watchDependency('model#/resources/kubedbComProxySQL/spec/init/initialized') - return !!initialized -} + function hasNoAnnotations() { + return !hasAnnotations() + } -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine + + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute/${type}` -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComProxySQL/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') + if (minMachine && maxMachine && instance !== minMaxMachine) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: { ...annotations }, + force: true, + }) + } } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + /************ Monitoring ************/ + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } + + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - if (owner && cluster && namespace) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, - }, - }, - }, + params: { filter: { items: { metadata: { name: null } } } }, }, ) - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) - }) + const resources = (resp && resp.data && resp.data.items) || [] - filteredSecrets.map((item) => { + resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' item.text = name item.value = name return true }) - return filteredSecrets + return resources } catch (e) { console.log(e) + return [] } } - return [] -} -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans + } + + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } + + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/secret_config', + path: '/resources/kubedbComProxySQL/spec/monitor', value: {}, force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComProxySQL/spec/monitor') } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/kubedbComProxySQL/spec/configSecret/name', - value: configSecretName, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) } -} -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/md-config.cnf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComProxySQL/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus } - return 'use-existing-config' -} -function onConfigurationValueChange({ discriminator, getValue, commit }, path) { - const value = getValue(discriminator, `/${path}`) - commit('wizard/model$update', { - path: `/resources/secret_config/stringData/${path}.cnf`, - value, - force: true, - }) -} - -function setCustomConfigConfigureChoice({ model, getValue }) { - const customConfig = getValue(model, '/resources/kubedbComProxySQL/spec/configSecret') - return customConfig ? 'yes' : 'no' -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComProxySQL/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComProxySQL/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComProxySQL/spec/monitor/prometheus/exporter') + } } -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/proxysqlopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations${ - reqType ? '&requestType=' + reqType : '' - }` -} - -function onMySQLRulesChange({ discriminator, getValue, commit }) { - const rules = getValue(discriminator, '/mysqlQueryRules') - const modifiedRules = rules?.map((item) => item.rules) - - commit('wizard/model$update', { - path: '/resources/kubedbComProxySQL/spec/initConfig/mysqlQueryRules', - value: modifiedRules, - force: true, - }) -} - -function setMySQLRules({ model, getValue, setDiscriminatorValue }) { - const rules = getValue(model, '/resources/kubedbComProxySQL/spec/initConfig/mysqlQueryRules') - const modifiedRules = rules?.map((item) => ({ rules: item })) - - setDiscriminatorValue('/mysqlQueryRules', modifiedRules) - - return modifiedRules -} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComProxySQL/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComProxySQL/spec/metadata/labels') -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + const agent = getValue(model, '/resources/kubedbComProxySQL/spec/monitor/agent') - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace', - value: namespace, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, force: true, }) } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComProxySQL/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } - }) -} + } -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/proxysqls/${name}`, + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` + + const isKube = !!storeGet('/route/params/actions') + + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/proxysqlopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations${ + reqType ? '&requestType=' + reqType : '' + }` + } + + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name', ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) } } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') - - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } } - clearSpecModel({ commit }, verd) - return type === verd && spec -} -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/${autoscaleType}/cluster`, - ) + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } -} -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute') -} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name', - ) - } -} + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, + }) -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) - return mappedList - } catch (e) { - console.log(e) } - return [] -} -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( model, - '/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + '/resources/kubedbComProxySQL/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -function setApplyToIfReady() { - return 'IfReady' -} + if (!configMapName) return [] -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' - commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, - force: true, - }) - } - } -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + const configMaps = (resp && resp.data && resp.data.data) || {} - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + return configMapKeys } catch (e) { console.log(e) return [] } } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - console.log(nodeGroups) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + const secrets = (resp && resp.data && resp.data.items) || [] - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } + } - return dependantIndex === -1 ? machines : filteredMachine -} + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComProxySQL/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - return !!instance -} + if (!secretName) return [] -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComProxySQLAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] + const secret = (resp && resp.data && resp.data.data) || {} - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComProxySQLAutoscaler/spec/compute/${type}` + return secretKeys + } catch (e) { + console.log(e) + return [] + } + } - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + function returnFalse() { + return false } -} -return { - isRancherManaged, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - getProxySQLVersions, - getAppBindings, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - disableInitializationSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - onConfigurationValueChange, - onSetCustomConfigChange, - setCustomConfigConfigureChoice, - getOpsRequestUrl, - onMySQLRulesChange, - setMySQLRules, - getCreateNameSpaceUrl, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + return { + isConsole, + isKubedb, + isRancherManaged, + showOpsRequestOptions, + getNamespaces, + getDbs, + getDbDetails, + initMetadata, + onNamespaceChange, + fetchNodeTopology, + isNodeTopologySelected, + setControlledResources, + setTrigger, + setApplyToIfReady, + fetchTopologyMachines, + setAllowedMachine, + getMachines, + hasAnnotations, + hasNoAnnotations, + onMachineChange, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + } } diff --git a/charts/kubedbcom-rabbitmq-editor-options/ui/create-ui.yaml b/charts/kubedbcom-rabbitmq-editor-options/ui/create-ui.yaml index d577e7c96b..b452a80dc0 100644 --- a/charts/kubedbcom-rabbitmq-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-rabbitmq-editor-options/ui/create-ui.yaml @@ -1,309 +1,290 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/RabbitMQ/versions - if: isToggleOn|databases/RabbitMQ/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/RabbitMQ/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/RabbitMQ/versions + if: + type: function + name: isToggleOn|databases/RabbitMQ/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/RabbitMQ/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/RabbitMQ/mode + loader: getAdminOptions|databases/RabbitMQ/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/RabbitMQ/mode + label: Database Mode + watcher: + func: onModeChange + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: showReplicaField + label: Replica number + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/RabbitMQ/mode - fetch: getAdminOptions|databases/RabbitMQ/mode - hasDescription: true - if: isToggleOn|databases/RabbitMQ/mode - label: - text: labels.database.mode - onChange: onModeChange - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - elements: - - if: showReplicaField - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas - type: input - type: single-step-form + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine Profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage Class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - label: Storage Size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete ( Keep only database Secrets and backed up data ) + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt ( Keep PVCs, database Secrets and backed up data ) + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut ( Delete everything including backed up data ) + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate ( Prevent deletion of the RabbitMQ CRD ) + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: showReferSecret + label: Password (leave it blank to auto generate password) + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + options: + - description: Postgres sharded cluster for high performance and high availability. + text: Shared + value: Shared + - description: For production applications with sophisticated workload requirements. + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + refresh: true + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + label: Advanced Configuration + showLabels: true + hideBlock: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring + type: switch + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - elements: + - label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + if: + type: function + name: isToggleOn|tls + type: block-layout + - elements: + - label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier - options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - elements: - - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - if: isToggleOn|tls - type: single-step-form - - elements: - - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - if: isToggleOn|expose - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|expose + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-rabbitmq-editor-options/ui/functions.js b/charts/kubedbcom-rabbitmq-editor-options/ui/functions.js index c6d69af1aa..a5eb8463d3 100644 --- a/charts/kubedbcom-rabbitmq-editor-options/ui/functions.js +++ b/charts/kubedbcom-rabbitmq-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1055 +317,1043 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} +let placement = [] +let versions = [] +let storageClass = [] +let clusterIssuers = [] +let nodetopologiesShared = [] +let nodetopologiesDedicated = [] +let features = [] -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Standalone', 'Cluster'] - return validType.includes(modelPathValue) -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showReplicaField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Replicaset'] - return validType.includes(modelPathValue) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('monitoring', false) -function onModeChange({ model, getValue, watchDependency, commit }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - if (modelPathValue === 'Replicaset') { - commit('wizard/model$update', { - path: '/spec/replicas', - value: 3, - force: true, - }) - } else { - commit('wizard/model$update', { - path: '/spec/replicas', - value: 1, - force: true, - }) + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value } -} -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function showAuthSecretField() { + return !showAuthPasswordField() + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Standalone', 'Cluster'] + return validType.includes(modelPathValue) + } - const resources = (resp && resp.data && resp.data.items) || [] + function showReplicaField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Replicaset'] + return validType.includes(modelPathValue) + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + function onModeChange() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + if (modelPathValue === 'Replicaset') { + commit('wizard/model$update', { + path: '/spec/replicas', + value: 3, + force: true, + }) + } else { + commit('wizard/model$update', { + path: '/spec/replicas', + value: 1, + force: true, + }) + } + } -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, }, - }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + async function getMongoDbVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, + }, + } - const resources = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const resources = (resp && resp.data && resp.data.items) || [] - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions -} + // keep only non deprecated versions + const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + filteredMongoDbVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMongoDbVersions } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } + } + + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const secrets = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + const secrets = (resp && resp.data && resp.data.items) || [] - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - } else { - array = machineList - .map((machine) => { + return filteredSecrets + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: comparePath, - value: memory, + path: commitPath, + value: val, force: true, }) - return memory - } else { + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + async function fetchJsons(itemCtx) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } + } + + function updateAgentValue(val) { commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', force: true, }) + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', force: true, }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + if (val === 'capz' && ifDedicated()) return true } -} - -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} - -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} - -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] - } + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function setStorageClass({ model, getValue, commit, watchDependency, discriminator }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } } - const isChangeable = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'storageClasses', - ) - if (isChangeable && storageClass) { - commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, - force: true, - }) + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, watchDependency, discriminator }, 'alert') - ) -} - -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - } catch (e) { - console.log(e) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/RabbitMQ/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/RabbitMQ/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/RabbitMQ/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') } - if (!features.includes('tls')) { + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - if (!features.includes('binding')) { + + function clearArbiterHidden() { commit('wizard/model$update', { - path: '/spec/admin/expose/default', + path: `/spec/arbiter/enabled`, value: false, force: true, }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { + commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', + path: `/spec/hidden/enabled`, value: false, force: true, }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } - - return returnArray -} -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + if (!getValue(model, `/spec/admin/databases/RabbitMQ/mode/toggle`)) { + let defMode = getDefault('databases/RabbitMQ/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/RabbitMQ/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + setDiscriminatorValue('/bundleApiLoaded', true) } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) - } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: path, + value: returnArray[0], force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + return returnArray + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + const options = getValue(model, `/spec/admin/${type}/available`) || [] - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } + + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } + } + + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } + + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list + + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} - -function returnFalse() { - return false -} - -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} + function returnFalse() { + return false + } -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } -} -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - returnFalse, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - showStorageSizeField, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - showStorageSizeField, - getResources, - getMongoDbVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - showReplicaField, - onModeChange, - setBackup, - showAdditionalSettings, - getDefault, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + initBundle, + getNamespaces, + updateAlertValue, + getAdminOptions, + isToggleOn, + showAlerts, + getNodeTopology, + clearArbiterHidden, + returnFalse, + showHidden, + isConfigDatabaseOn, + notEqualToDatabaseMode, + filterNodeTopology, + onAuthChange, + setMonitoring, + isMachineNotCustom, + isMachineCustom, + showIssuer, + showArbiter, + clearConfiguration, + showStorageSizeField, + onBackupSwitch, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + showAuthSecretField, + getResources, + getMongoDbVersions, + onCreateAuthSecretChange, + getSecrets, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + showReplicaField, + onModeChange, + setBackup, + showAdditionalSettings, + getDefault, + } } diff --git a/charts/kubedbcom-rabbitmq-editor/ui/edit-ui.yaml b/charts/kubedbcom-rabbitmq-editor/ui/edit-ui.yaml index 1e6fc178bb..a9daee0240 100644 --- a/charts/kubedbcom-rabbitmq-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-rabbitmq-editor/ui/edit-ui.yaml @@ -1,641 +1,533 @@ -steps: -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata +type: multi-step-form +step: +- type: single-step-form + id: compute-autoscaler + loader: getDbDetails + elements: + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComRabbitMQAutoscaler/spec/compute/rabbitmq/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string + # rabbitmq mode + - type: block-layout + label: RabbitMQ + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|rabbitmq - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|rabbitmq - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|rabbitmq - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/controlledResources - type: multiselect - label: - text: RabbitMQ - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComRabbitMQAutoscaler/spec/compute/rabbitmq/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|rabbitmq + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|rabbitmq + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|rabbitmq + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply +- type: single-step-form + id: storage-autoscaler + elements: + - type: block-layout + showLabels: false elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComRabbitMQ/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: RabbitMQ + showLabels: true + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComRabbitMQAutoscaler/spec/storage/rabbitmq/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComRabbitMQ/spec/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComRabbitMQAutoscaler/spec/storage/rabbitmq/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComRabbitMQAutoscaler/spec/storage/rabbitmq/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + +- type: single-step-form + id: monitoring + elements: + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComRabbitMQ/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection + elements: + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label + - text: Prometheus Operator value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComRabbitMQ/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComRabbitMQ/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComRabbitMQ/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComRabbitMQ/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComRabbitMQ/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComRabbitMQ/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - computed: getDbDetails - if: returnFalse - type: input - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComRabbitMQAutoscaler/spec/storage/rabbitmq/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/scalingRules/items/properties/appliesUpto type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComRabbitMQAutoscaler/spec/storage/rabbitmq/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComRabbitMQAutoscaler/spec/storage/rabbitmq/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/storage/properties/rabbitmq/properties/upperBound - type: input - label: - text: RabbitMQ - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/compute/properties/rabbitmq - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRabbitMQAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.10.label -- form: - discriminator: - binding: - default: false - type: boolean - elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComRabbitMQ/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + + +- type: single-step-form id: binding - title: Gateway Binding -type: multi-step-form + label: Gateway Binding + elements: + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-rabbitmq-editor/ui/functions.js b/charts/kubedbcom-rabbitmq-editor/ui/functions.js index 66580c8e84..9cee3450bd 100644 --- a/charts/kubedbcom-rabbitmq-editor/ui/functions.js +++ b/charts/kubedbcom-rabbitmq-editor/ui/functions.js @@ -1,1391 +1,373 @@ -// ************************* common functions ******************************************** -// eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } - - return ans -} - -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -function returnTrue() { - return true -} - -function returnStringYes() { - return 'yes' -} -function setAddressType({ model, getValue }) { - const value = getValue(model, '/resources/kubedbComRabbitMQ/spec/useAddressType') - - if (!value) { - return 'DNS' - } - - return value -} - -// ************************* Basic Info ********************************************** -async function getRabbitMQVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) - - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] - } -} - -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue }) { - const replicas = getValue(model, '/resources/kubedbComRabbitMQ/spec/replicas') - - return replicas === 1 ? 'Standalone' : 'Cluster' -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} - -const onDatabaseModeChange = ({ discriminator, getValue, commit }) => { - const databaseMode = getValue(discriminator, '/activeDatabaseMode') - - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/replicas', - value: databaseMode === 'Standalone' ? 1 : 3, - force: true, - }) -} - -// ************************** TLS ******************************88 - -function setApiGroup() { - return 'cert-manager.io' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComRabbitMQ/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComRabbitMQ/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComRabbitMQ/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComRabbitMQ/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } - - if (!url) return [] - - try { - const resp = await axios.get(url) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComRabbitMQ/spec/sslMode') - return val || 'require' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/monitor/prometheus/exporter') - } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComRabbitMQ/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( model, - '/resources/stashAppscodeComRestoreSession_init', + store.state, ) - const script = getValue(model, '/resources/kubedbComRabbitMQ/spec/init/script') - - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComRabbitMQ/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComRabbitMQ/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/init/script') + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', true) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Compute Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + // monitoring + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } + + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) + const resources = (resp && resp.data && resp.data.items) || [] - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) + return resources + } catch (e) { + console.log(e) + return [] } } -} -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComRabbitMQ/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComRabbitMQ/spec/init/script/secret/secretName') - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/init/script/secret') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - if (!valueExists(model, getValue, '/resources/kubedbComRabbitMQ/spec/init/script/configMap')) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/init/script/configMap', - value: { - name: '', + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, }, }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/init/script/configMap') - if (!valueExists(model, getValue, '/resources/kubedbComRabbitMQ/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/init/script/secret', - value: { - secretName: '', - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) + return ans } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} + /****** Monitoring *********/ -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus } -} -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', + path: '/resources/kubedbComRabbitMQ/spec/monitor', value: {}, force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/monitor') } - } -} -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule bakcup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComRabbitMQAnnotations = - getValue(model, '/resources/kubedbComRabbitMQ/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComRabbitMQAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', + force: true, + }) } -} - -function deleteKubeDbComRabbitMQDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComRabbitMQ/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/metadata/annotations', - value: filteredAnnotations, - }) -} -function addKubeDbComRabbitMQDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComRabbitMQ/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus } - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComRabbitMQ annotation - deleteKubeDbComRabbitMQDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, + path: '/resources/kubedbComRabbitMQ/spec/monitor/prometheus/exporter', + value: {}, force: true, }) + } else { + commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/monitor/prometheus/exporter') } } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - if (scheduleBackup === 'yes') return true - else return false -} - -// invoker form -function initBackupInvoker({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } - if (stashAppscodeComBackupConfiguration) return 'backupConfiguration' - else if (isBluePrint) return 'backupBlueprint' - else return undefined -} + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComRabbitMQ/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function onBackupInvokerChange({ getValue, discriminator, commit, model }) { - const backupInvoker = getValue(discriminator, '/backupInvoker') + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComRabbitMQ/spec/metadata/labels') - if (backupInvoker === 'backupConfiguration') { - // delete annotation and create backup config object - deleteKubeDbComRabbitMQDbAnnotation(getValue, model, commit) - const dbName = getValue(model, '/metadata/release/name') + const agent = getValue(model, '/resources/kubedbComRabbitMQ/spec/monitor/agent') - if (!valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration')) { + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, force: true, }) } - } else if (backupInvoker === 'backupBlueprint') { - // delete backup configuration object and create the annotation - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - addKubeDbComRabbitMQDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - '', - ) } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComRabbitMQ/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComRabbitMQ/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComRabbitMQDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComRabbitMQDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComRabbitMQ/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComRabbitMQ/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) } -} -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComRabbitMQ/spec/metadata/labels') + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - const agent = getValue(model, '/resources/kubedbComRabbitMQ/spec/monitor/agent') + const isKube = !!storeGet('/route/params/actions') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/rabbitmqopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` } -} -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComRabbitMQ/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComRabbitMQ/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name', + ) } } - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' } } - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) - } + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, - force: true, + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - } -} -function returnFalse() { - return false -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComRabbitMQ/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComRabbitMQ/spec/authSecret') - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComRabbitMQ/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} + if (!configMapName) return [] -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComRabbitMQ/spec/init/initialized') - watchDependency('model#/resources/kubedbComRabbitMQ/spec/init/initialized') - return !!initialized -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} + const configMaps = (resp && resp.data && resp.data.data) || {} -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') + return configMapKeys + } catch (e) { + console.log(e) + return [] + } } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - if (owner && cluster && namespace) { try { const resp = await axios.get( `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, { params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, - }, - }, + filter: { items: { metadata: { name: null }, type: null } }, }, }, ) @@ -1393,11 +375,7 @@ async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) const secrets = (resp && resp.data && resp.data.items) || [] const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] + const validType = ['kubernetes.io/service-account-token', 'Opaque'] return validType.includes(item.type) }) @@ -1410,821 +388,527 @@ async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) return filteredSecrets } catch (e) { console.log(e) + return [] } } - return [] -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/user.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComRabbitMQ/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) -function onConfigurationChangeEdit({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - - commit('wizard/model$update', { - path: '/resources/secret_config/data/rabbitmq.ini', - value: btoa(value), - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} + if (!secretName) return [] -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/user.conf') -} + const secret = (resp && resp.data && resp.data.data) || {} -function setConfigurationForEdit({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/rabbitmq.ini') - return atob(value) -} + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/user.conf') - return atob(value) -} + return secretKeys + } catch (e) { + console.log(e) + return [] + } + } -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') + // storage - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComRabbitMQ/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } + } } -} -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/rabbitmqopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} + // compute -const getAppbinding = async ({ axios, storeGet, getValue, watchDependency, rootModel }) => { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + let autoscaleType = '' + let dbDetails = {} - const group = 'appcatalog.appscode.com' - const version = 'v1alpha1' - const resource = 'appbindings' + function isConsole() { + const isKube = isKubedb() - watchDependency('rootModel#/databaseRef/namespace') + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } + } - const namespace = getValue(rootModel, '/databaseRef/namespace') + return !isKube + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + function isKubedb() { + return !!storeGet('/route/params/actions') + } - const resources = (resp && resp.data && resp.data.items) || [] + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) -function onRefChange({ discriminator, getValue, commit }) { - const ref = getValue(discriminator, '/pgRef') || {} - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/database/databaseRef/name', - value: ref.name || '', - force: true, - }) - commit('wizard/model$update', { - path: '/resources/kubedbComRabbitMQ/spec/database/databaseRef/namespace', - value: ref.namespace || '', - force: true, - }) -} + const resources = (resp && resp.data && resp.data.items) || [] -async function getAppBindings({ axios, storeGet }, type) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const queryParams = { - filter: { - items: { - metadata: { name: null, namespace: null }, - spec: { type: null }, - }, - }, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { + + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - queryParams, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, ) + const resources = (resp && resp.data && resp.data.items) || [] - const fileredResources = resources - .filter((item) => item.spec?.type === `kubedb.com/${type}`) - .map((item) => { - const name = item.metadata?.name || '' - const namespace = item.metadata?.namespace || '' - return { - text: `${namespace}/${name}`, - value: { - name: name, - namespace: namespace, - }, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } -} -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} - -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name') || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/rabbitmqs/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - if (isKube) { - const dbName = storeGet('/route/params/name') || '' commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name', - value: dbName, + path: `/metadata/release/name`, + value: name, force: true, }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/name', - value: modifiedName, + path: `/metadata/release/namespace`, + value: namespace, force: true, }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, + }) + } + + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name') || + '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace', - value: namespace, + path: '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/name', + value: modifiedName, force: true, }) - } - } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute', + ) + } -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name', + ) + } + } -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] + } - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } - const resources = (resp && resp.data && resp.data.items) || [] + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, + }) + return list + } - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function setApplyToIfReady() { + return 'IfReady' + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + async function fetchTopologyMachines() { + const instance = hasAnnotations() - const resources = (resp && resp.data && resp.data.items) || [] + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } } - }) -} + } -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function setAllowedMachine(minmax) { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/rabbitmqs/${name}`, - ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) - } + if (minmax === 'min') return mn + else return mx } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` -async function dbTypeEqualsTo({ watchDependency, commit }, type) { - watchDependency('discriminator#/dbDetails') + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'combined' - } - clearSpecModel({ commit }, verd) - return type === verd && spec -} + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/${autoscaleType}/cluster`, - ) - } -} + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/name', - value: modifiedName, - force: true, + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } }) - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name', + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, ) + + return dependantIndex === -1 ? machines : filteredMachine } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/annotations') || + {} + const instance = annotations['kubernetes.io/instance-type'] -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + return !!instance } - return [] -} -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} + function hasNoAnnotations() { + return !hasAnnotations() + } -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) + const instance = annotations['kubernetes.io/instance-type'] -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine -function setApplyToIfReady() { - return 'IfReady' -} + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute/${type}` -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, force: true, }) - } - } else { - if (!isNaN(value)) { - value += 'Gi' commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, + path: annoPath, + value: { ...annotations }, force: true, }) } } -} -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComRabbitMQBinding') - return isExposeBinding -} + // binding -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 labels = getValue(model, '/resources/kubedbComRabbitMQ/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'RabbitMQBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComRabbitMQ/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'PostgresBinding', + metadata: { + labels, name: dbName, namespace: dbNamespace, }, - }, - } - - if (value) { - await commit('wizard/model$update', { - path: '/resources/catalogAppscodeComRabbitMQBinding', - value: bindingValues, - force: true, - }) - } else { - await commit('wizard/model$delete', '/resources/catalogAppscodeComRabbitMQBinding') - } -} - -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) - - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComRabbitMQBinding', + value: bindingValues, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComRabbitMQBinding') } } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComRabbitMQAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComRabbitMQBinding') + return isExposeBinding + } - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComRabbitMQAutoscaler/spec/compute/${type}` + function returnFalse() { + return false + } - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value } -} -return { - isRancherManaged, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - isVariantAvailable, - fetchJsons, - getAppbinding, - onDatabaseModeChange, - setDatabaseMode, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - setAddressType, - getRabbitMQVersions, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - valueExists, - onConfigurationChangeEdit, - setConfigurationForEdit, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComRabbitMQDbAnnotation, - addKubeDbComRabbitMQDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - setConfigurationForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - disableInitializationSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - onRefChange, - getAppBindings, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + return { + returnFalse, + isEqualToModelPathValue, + getResources, + showMonitoringSection, + onEnableMonitoringChange, + showCustomizeExporterSection, + onCustomizeExporterChange, + isValueExistInModel, + onNamespaceChange, + onLabelChange, + onAgentChange, + getOpsRequestUrl, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConsole, + isKubedb, + showOpsRequestOptions, + getNamespaces, + getDbs, + isRancherManaged, + getDbDetails, + initMetadata, + fetchNodeTopology, + isNodeTopologySelected, + setControlledResources, + setTrigger, + setApplyToIfReady, + fetchTopologyMachines, + setAllowedMachine, + getMachines, + hasAnnotations, + hasNoAnnotations, + onMachineChange, + addOrRemoveBinding, + isBindingAlreadyOn, + handleUnit, + setValueFromDbDetails, + } } diff --git a/charts/kubedbcom-redis-editor-options/ui/create-ui.yaml b/charts/kubedbcom-redis-editor-options/ui/create-ui.yaml index 6d18c8dcc7..c1b9f887e9 100644 --- a/charts/kubedbcom-redis-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-redis-editor-options/ui/create-ui.yaml @@ -1,427 +1,375 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Redis/versions - if: isToggleOn|databases/Redis/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Redis/properties/versions/properties/default - type: select - - computed: getDefault|databases/Redis/mode - fetch: getAdminOptions|databases/Redis/mode - hasDescription: true - if: isToggleOn|databases/Redis/mode - label: - text: labels.database.mode - schema: - $ref: schema#/properties/spec/properties/mode +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/Redis/versions + if: + type: function + name: isToggleOn|databases/Redis/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Redis/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Redis/mode + loader: getAdminOptions|databases/Redis/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/Redis/mode + label: Database Mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Cluster|/spec/mode + label: Shards + schema: schema/properties/spec/properties/cluster/properties/master + type: input + - if: + type: function + name: isEqualToModelPathValue|Cluster|/spec/mode + label: Replica Number + schema: schema/properties/spec/properties/cluster/properties/replicas + type: input + - elements: + - init: + type: func + value: returnTrue + label: Sentinel Type + watcher: + func: onCreateSentinelChange + paths: + - temp/createSentinel + options: + - text: Use Existing Sentinel + value: "false" + - text: Create New Sentinel + value: "true" + schema: temp/createSentinel type: radio - - if: isEqualToModelPathValue|Cluster|/spec/mode - label: - text: labels.shards - schema: - $ref: schema#/properties/spec/properties/cluster/properties/master + - loader: getResources|core|v1|namespaces + if: + type: function + name: showSentinelNameAndNamespace + label: Namespace + schema: schema/properties/spec/properties/sentinelRef/properties/namespace + type: select + - loader: getRedisSentinels + if: + type: function + name: showSentinelNameAndNamespace + label: Name + schema: schema/properties/spec/properties/sentinelRef/properties/name + type: select + - label: Replica Number + schema: schema/properties/spec/properties/replicas type: input - - if: isEqualToModelPathValue|Cluster|/spec/mode - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/cluster/properties/replicas + if: + type: function + name: isEqualToModelPathValue|Sentinel|/spec/mode + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - discriminator: - announce: - default: false - type: boolean - createSentinel: - default: true - type: boolean - elements: - - label: - text: labels.sentinel_section - type: label-element - - onChange: onCreateSentinelChange - options: - - text: options.sentinelType.existingSentinel.label - value: false - - text: options.sentinelType.customSentinel.label - value: true - schema: - $ref: discriminator#/properties/createSentinel - type: radio - - fetch: getResources|core|v1|namespaces - if: showSentinelNameAndNamespace - keepEmpty: true - label: - text: labels.namespace - schema: - $ref: schema#/properties/spec/properties/sentinelRef/properties/namespace - type: select - - allowUserDefinedOption: true - fetch: getRedisSentinels - if: showSentinelNameAndNamespace - keepEmpty: true - label: - text: labels.name - schema: - $ref: schema#/properties/spec/properties/sentinelRef/properties/name - type: select - - label: - text: labels.replicaset.number - minValue: 2 - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: notEqualToDatabaseMode|Sharded + label: Machine profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + label: Storage Class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: isNotEqualToModelPathValue|Sentinel|/spec/mode + label: Storage Size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - init: + type: func + value: setAnnounce + label: Announce Redis Endpoints ? + watcher: + func: setAnnounce + paths: + - temp/announce + schema: temp/announce + type: switch + - elements: + - label: Type + options: + - text: ip + value: ip + - text: hostname + value: hostname + schema: schema/properties/spec/properties/cluster/properties/announce/properties/type + type: select + - type: array-item-form + element: + label: Shard Endpoints (comma-separated, e.g. "endpoint1,endpoint2,endpoint3") + schema: schema/properties/spec/properties/cluster/properties/announce/properties/shards/items type: input - if: isEqualToModelPathValue|Sentinel|/spec/mode - type: single-step-form + label: Shards + schema: schema/properties/spec/properties/cluster/properties/announce/properties/shards + if: + type: function + name: showAnnounce + label: Announce + showLabels: true + type: block-layout + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - if: notEqualToDatabaseMode|Sharded - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + hideBlock: true + label: Labels & Annotations + showLabels: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete ( Keep only database Secrets and backed up data ) + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt ( Keep PVCs, database Secrets and backed up data ) + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut ( Delete everything including backed up data ) + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate ( Prevent deletion of the Redis CRD ) + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - if: isNotEqualToModelPathValue|Sentinel|/spec/mode - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password (leave it blank to auto generate password) + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - computed: setAnnounce - if: isEqualToModelPathValue|Cluster|/spec/mode - label: - text: Announce Redis Endpoints ? - onChange: setAnnounce - schema: - $ref: discriminator#/announce + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + options: + - description: For exploring databases when high-performance is not required. + text: Shared + value: Shared + - description: For production applications with sophisticated workload + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + hideBlock: true + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: - elements: - - label: - text: Type - options: - - ip - - hostname - required: true - schema: - $ref: schema#/properties/spec/properties/cluster/properties/announce/properties/type - type: select - - addFormLabel: Shards - element: - elements: - - element: - label: - text: Endpoints - schema: - $ref: schema#/properties/spec/properties/cluster/properties/announce/properties/shards/items/properties/endpoints/items - type: input - label: - text: Endpoints - schema: - $ref: schema#/properties/spec/properties/cluster/properties/announce/properties/shards/items/properties/endpoints - type: list-input-form - type: single-step-form - label: - text: Shards - newItemValidator: validateEndpoints - required: true - schema: - $ref: schema#/properties/spec/properties/cluster/properties/announce/properties/shards - tableContents: - - inTableColumn: true - label: - text: Endpoints - path: endpoints - type: value - typeOfValue: string - temporaryPath: /endpoints - type: single-step-form-array - validationRuleObject: - func: isAnnounceValid - if: showAnnounce - label: - text: Announce - schema: - $ref: schema#/properties/spec/properties/cluster/properties/announce - show_label: true - type: single-step-form - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase - type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - refresh: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default + type: switch + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + if: + type: function + name: isToggleOn|tls + type: block-layout + - elements: + - if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - if: isToggleOn|tls - type: single-step-form - - elements: - - if: isToggleOn|expose - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-redis-editor-options/ui/functions.js b/charts/kubedbcom-redis-editor-options/ui/functions.js index 9537b050e9..cf7cc0657f 100644 --- a/charts/kubedbcom-redis-editor-options/ui/functions.js +++ b/charts/kubedbcom-redis-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -319,1087 +321,1092 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} - -function isNotEqualToModelPathValue( - { model, getValue, watchDependency, discriminator }, - value, - modelPath, -) { - const modelPathValue = getValue(model, modelPath, getValue) - watchDependency('model#' + modelPath) - return ( - modelPathValue !== value && - isToggleOn({ getValue, model, watchDependency, discriminator }, 'storageClasses') +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, ) -} - -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('createSentinel', 'true') + setDiscriminatorValue('announce', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('monitoring', false) + setDiscriminatorValue('backup', false) + + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } + } - const resources = (resp && resp.data && resp.data.items) || [] + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } -async function getRedisSentinels({ axios, storeGet, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/spec/sentinelRef/namespace') + function dedicatedOnChange() { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } - watchDependency('model#/spec/sentinelRef/namespace') + async function fetchJsons(itemCtx) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - if (owner && cluster && namespace) { try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redissentinels`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } + } - const resources = (resp && resp.data && resp.data.items) || [] + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, }) - - return resources - } catch (err) { - console.log(err) - return [] } - } else { - return [] + + return returnArray } -} -async function getRedisVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - const resources = (resp && resp.data && resp.data.items) || [] + const options = getValue(model, `/spec/admin/${type}/available`) || [] - // keep only non deprecated versions - const filteredRedisVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options + } - filteredRedisVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredRedisVersions -} + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } + } - const secrets = (resp && resp.data && resp.data.items) || [] + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + if (available.length) { + array = available.map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } + }) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array + } -function showSentinelNameAndNamespace({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/createSentinel') - const verd = getValue(discriminator, '/createSentinel') + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] + } - return !verd -} + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] -function onCreateSentinelChange({ discriminator, getValue, commit }) { - const verd = getValue(discriminator, '/createSentinel') + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - if (verd) { - commit('wizard/model$update', { - path: '/spec/sentinelRef/name', - value: '', - force: true, - }) + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - commit('wizard/model$update', { - path: '/spec/sentinelRef/namespace', - value: '', - force: true, - }) + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList } -} -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + async function getRedisSentinels() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/spec/sentinelRef/namespace') - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } + // watchDependency('model#/spec/sentinelRef/namespace') - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} + if (owner && cluster && namespace) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redissentinels`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + const resources = (resp && resp.data && resp.data.items) || [] -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + return resources + } catch (err) { + console.log(err) + return [] + } + } else { + return [] + } } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + async function getRedisVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, + }, + } - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const resources = (resp && resp.data && resp.data.items) || [] -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + // keep only non deprecated versions + const filteredRedisVersions = resources.filter((item) => item.spec && !item.spec.deprecated) -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + filteredRedisVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredRedisVersions } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { + const options = [] try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) }) - return val } catch (e) { console.log(e) - return [] } + return options } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { - try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } + + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) + + const secrets = (resp && resp.data && resp.data.items) || [] + + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } + + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } }) - url = url.slice(0, -1) + return val + } catch (e) { + console.log(e) + return [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val - } catch (e) { - console.log(e) - return [] } } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function setStorageClass({ model, getValue, commit, watchDependency, discriminator }) { - const deletionPolicy = getValue(model, 'spec/deletionPolicy') || '' - let storageClass = getValue(model, 'spec/storageClass/name') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true } - const isChangeable = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'storageClasses', - ) - if (isChangeable && storageClass) { + + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } + commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!getValue(model, `/spec/admin/databases/Redis/mode/toggle`)) { + let defMode = getDefault('databases/Redis/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Redis/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } + + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', force: true, }) } - } catch (e) { - console.log(e) + + setDiscriminatorValue('/bundleApiLoaded', true) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) + function isAnnounceValid() { + // watchDependency('model#/spec/cluster/master') - if (!getValue(model, `/spec/admin/databases/Redis/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Redis/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Redis/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + const master = getValue(model, '/spec/cluster/master') || 0 + + const shards = getValue(model, '/spec/cluster/announce/shards') || [] + const shardsLength = shards?.length || 0 + + if (shardsLength !== master) return `Shards Length should be equal to master(${master})` + return true } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) + + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue } - if (!features.includes('monitoring')) { + + function isNotEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue !== value && isToggleOn('storageClasses') + } + + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } + + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } + + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } + + function onAuthChange() { commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', + path: '/spec/authSecret/name', value: '', force: true, }) commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', + path: '/spec/authSecret/password', + value: '', force: true, }) } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) + + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { path: '/spec/backup/tool', - value: '', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} + function onCreateSentinelChange() { + const verd = getValue(discriminator, '/createSentinel') -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') + if (verd) { + commit('wizard/model$update', { + path: '/spec/sentinelRef/name', + value: '', + force: true, + }) - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + commit('wizard/model$update', { + path: '/spec/sentinelRef/namespace', + value: '', + force: true, + }) + } } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` + function onReferSecretChange() { commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/authSecret/name', + value: '', force: true, }) } - return returnArray -} - -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - - const options = getValue(model, `/spec/admin/${type}/available`) || [] - - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + function returnFalse() { + return false } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + function setAnnounce() { + commit('wizard/model$update', { + path: '/spec/cluster/announce', + value: null, + force: true, + }) } - const backupVal = getValue(model, '/spec/backup/tool') - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } + } + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: comparePath, + value: memory, force: true, }) + return memory + } else { + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = `/spec/podResources/resources/limits/${resource}` + commit('wizard/model$update', { + path: commitPath, + value: val, + force: true, + }) + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function setStorageClass() { + const deletionPolicy = getValue(model, 'spec/deletionPolicy') || '' + let storageClass = getValue(model, 'spec/storageClass/name') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - ) + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - ) - }) - } else return filteredlist -} -function returnFalse() { - return false -} + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] } else { - return resp.data?.status?.namespaces || [] + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { + commit('wizard/model$update', { + path: '/spec/admin/storageClasses/default', + value: storageClass, + force: true, + }) } - } catch (e) { - console.log(e) } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, watchDependency, discriminator }, 'alert') - ) -} + function showAnnounce() { + // watchDependency('discriminator#/announce') + const isAnnounceEnable = getValue(discriminator, '/announce') + return isAnnounceEnable + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showAuthSecretField() { + return !showAuthPasswordField() + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + if (val === 'capz' && ifDedicated()) return true + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue } -} -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } - }) - .filter((val) => !!val) + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory - } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue - } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory - } + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } + + function showSentinelNameAndNamespace() { + // watchDependency('discriminator#/createSentinel') + const verd = getValue(discriminator, '/createSentinel') + + return verd === 'false' || verd === false } - if (resource === 'memory') { + function updateAgentValue(val) { commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', force: true, }) + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: memory, + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', force: true, }) - return memory - } else { + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} - -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} - -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} - -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} - -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function validateEndpoints() { + // watchDependency('model#/spec/cluster/replicas') -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} - -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + const replicas = getValue(model, '/spec/cluster/replicas') || 0 -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + const endpoints = storeGet('/wizard/temporaryModel/endpoints') + const endpointsObject = Object.values(endpoints) + const length = Object.keys(endpointsObject?.[0])?.length + if (length !== replicas) + return { isInvalid: true, message: `Endpoints length should be equal to replicas(${replicas})` } + else { + return {} + } } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function zonesOnChange() { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} - -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} - -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} - -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} - -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} - -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} - -function setAnnounce({ commit }) { - commit('wizard/model$update', { - path: '/spec/cluster/announce', - value: null, - force: true, - }) -} - -function showAnnounce({ getValue, discriminator, watchDependency }) { - watchDependency('discriminator#/announce') - const isAnnounceEnable = getValue(discriminator, '/announce') - return isAnnounceEnable -} - -function isAnnounceValid({ getValue, model, watchDependency }) { - watchDependency('model#/spec/cluster/master') - - const master = getValue(model, '/spec/cluster/master') || 0 - - const shards = getValue(model, '/spec/cluster/announce/shards') || [] - const shardsLength = shards?.length || 0 - - if (shardsLength !== master) return `Shards Length should be equal to master(${master})` - return true -} - -function validateEndpoints({ getValue, model, watchDependency, storeGet }) { - watchDependency('model#/spec/cluster/replicas') - - const replicas = getValue(model, '/spec/cluster/replicas') || 0 - - const endpoints = storeGet('/wizard/temporaryModel/endpoints') - const endpointsObject = Object.values(endpoints) - const length = Object.keys(endpointsObject?.[0])?.length - if (length !== replicas) - return { isInvalid: true, message: `Endpoints length should be equal to replicas(${replicas})` } - else { - return {} + function returnTrue() { + return 'true' } -} -return { - validateEndpoints, - isAnnounceValid, - showAnnounce, - setAnnounce, - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - isNotEqualToModelPathValue, - showAuthSecretField, - getResources, - getRedisSentinels, - getRedisVersions, - getSecrets, - setMachineToCustom, - showSentinelNameAndNamespace, - onCreateSentinelChange, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - getAdminOptions, - isToggleOn, - getNamespaces, - getNodeTopology, - filterNodeTopology, - updateAlertValue, - showAlerts, - onBackupSwitch, - showIssuer, - setMonitoring, - clearConfiguration, - isConfigDatabaseOn, - getMachineListForOptions, - setLimits, - setRequests, - isMachineNotCustom, - isMachineCustom, - notEqualToDatabaseMode, - onAuthChange, - setBackup, - showAdditionalSettings, - getDefault, + return { + checkIfFeatureOn, + clearConfiguration, + dedicatedOnChange, + fetchJsons, + fetchOptions, + filterNodeTopology, + getAdminOptions, + getCreateNameSpaceUrl, + getDefault, + getDefaultValue, + getMachineListForOptions, + getNamespaces, + getNodeTopology, + getRedisSentinels, + getRedisVersions, + getReferSecrets, + getResources, + getSecrets, + getSKU, + getZones, + ifCapiProviderIsNotEmpty, + ifDedicated, + ifZones, + initBundle, + isAnnounceValid, + isConfigAvailable, + isConfigDatabaseOn, + isEqualToModelPathValue, + isMachineCustom, + isMachineNotCustom, + isNotEqualToModelPathValue, + isRancherManaged, + isToggleOn, + isVariantAvailable, + notEqualToDatabaseMode, + onAuthChange, + onBackupSwitch, + onCreateSentinelChange, + onReferSecretChange, + returnFalse, + returnTrue, + setAnnounce, + setBackup, + setLimits, + setMachineToCustom, + setMonitoring, + setRequests, + setStorageClass, + showAdditionalSettings, + showAlerts, + showAnnounce, + showAuthPasswordField, + showAuthSecretField, + showIssuer, + showMultiselectZone, + showReferSecret, + showReferSecretSwitch, + showSecretDropdown, + showSelectZone, + showSentinelNameAndNamespace, + updateAgentValue, + updateAlertValue, + validateEndpoints, + zonesOnChange, + } } diff --git a/charts/kubedbcom-redis-editor/ui/edit-ui.yaml b/charts/kubedbcom-redis-editor/ui/edit-ui.yaml index d57332048d..1695e2bcd1 100644 --- a/charts/kubedbcom-redis-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-redis-editor/ui/edit-ui.yaml @@ -1,1758 +1,870 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - - disabled: true - fetch: getResources|core|v1|namespaces - label: - text: labels.namespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - disableUnselect: true - disabled: true - fetch: getRedisVersions|catalog.kubedb.com|v1alpha1|redisversions - label: - text: labels.database.version - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/version - type: select - - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - onChange: onLabelChange - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/metadata/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/metadata/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/metadata/properties/annotations/additionalProperties - type: input - - hasDescription: true - label: - text: labels.deletionPolicy - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/deletionPolicy - type: radio - - disabled: true - label: - text: labels.secret - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/authSecret/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - elements: - - alias: reusable_alert - chart: - name: uibytebuildersdev-component-alert - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/form/properties/alert - type: reusable-element - type: single-step-form - id: alert - title: labels.alert -- form: +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - if: isNotEqualToModelPathValue|Standalone|/resources/kubedbComRedis/spec/mode - label: - text: labels.to_update_disabled_section - type: label-element - - customClass: mb-20 - if: isNotEqualToModelPathValue|Standalone|/resources/kubedbComRedis/spec/mode - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/redisopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations - - computed: setDatabaseMode - disabled: true - hasDescription: true - label: - text: labels.database.mode - onChange: deleteDatabaseModePath + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - description: options.database.mode.Standalone.description - text: options.database.mode.Standalone.label - value: Standalone - - description: options.database.mode.Cluster.description - text: options.database.mode.Cluster.label - value: Cluster - - description: options.database.mode.Sentinel.description - text: options.database.mode.Sentinel.label - value: Sentinel - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/mode - type: radio - - disabled: true - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/cluster/properties/replicas - type: input - - label: - text: labels.master - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/cluster/properties/shards - type: input - if: isEqualToModelPathValue|Cluster|/resources/kubedbComRedis/spec/mode - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/cluster - type: single-step-form - - disabled: true - if: isEqualToModelPathValue|Sentinel|/resources/kubedbComRedis/spec/mode - label: - text: labels.replicaset.number - minValue: 2 - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/replicas - type: input - - disabled: true - discriminator: - createSentinel: - type: boolean + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - label: - text: labels.sentinel_section - type: label-element - - computed: setCreateSentinel - onChange: onCreateSentinelChange - options: - - text: options.sentinelType.existingSentinel.label - value: false - - text: options.sentinelType.customSentinel.label - value: true - schema: - $ref: discriminator#/properties/createSentinel - type: radio - - fetch: getResources|core|v1|namespaces - if: showSentinelNameAndNamespace - label: - text: labels.namespace - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/sentinelRef/properties/namespace - type: select - - allowUserDefinedOption: true - fetch: getRedisSentinels - if: showSentinelNameAndNamespace - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/sentinelRef/properties/name - type: select - if: isEqualToModelPathValue|Sentinel|/resources/kubedbComRedis/spec/mode - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/sentinelRef - type: single-step-form - - disabled: true - elements: - - fetch: getStorageClassNames - label: - text: labels.storage.class - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/storage/properties/storageClassName - type: select - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/storage/properties/resources/properties/requests/properties/storage - type: input - if: isNotEqualToModelPathValue|Sentinel|/resources/kubedbComRedis/spec/mode - type: single-step-form - type: single-step-form - id: topology - title: steps.1.label -- form: - discriminator: - configureTLS: - default: true - type: boolean - elements: - - label: - text: labels.to_update_tls - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/redisopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=ReconfigureTLS - - computed: isValueExistInModel|/resources/kubedbComRedis/spec/tls - disabled: true - label: - text: labels.enable_tls - onChange: onTlsConfigureChange - schema: - $ref: discriminator#/configureTLS - type: switch - - disabled: true - elements: - - elements: - - computed: setApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - label: - text: labels.kind + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - fetch: getIssuerRefsName - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - label: - text: labels.issuer_ref - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: showTlsConfigureSection - type: single-step-form - type: single-step-form - id: tls - title: steps.2.label -- form: + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig + elements: + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - disabled: disableInitializationSection - discriminator: - prePopulateDatabase: - type: string - elements: - - computed: initPrePopulateDatabase - label: - text: labels.prePopulateDatabase - onChange: onPrePopulateDatabaseChange + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/prePopulateDatabase - type: radio - - discriminator: - dataSource: - type: string + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines elements: - - computed: initDataSource - label: - text: labels.dataSource - onChange: onDataSourceChange - options: - - text: options.dataSource.script.text - value: script - - text: options.dataSource.stashBackup.text - value: stashBackup - schema: - $ref: discriminator#/properties/dataSource - type: select - - discriminator: - sourceVolumeType: - type: string - elements: - - label: - text: labels.script.path - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/init/properties/script/properties/scriptPath - type: input - - label: - text: labels.script.volume - type: label-element - - computed: initVolumeType - label: - text: labels.script.volumeType - onChange: onVolumeTypeChange - options: - - text: options.scriptSourceVolumeType.configMap.text - value: configMap - - text: options.scriptSourceVolumeType.secret.text - value: secret - schema: - $ref: discriminator#/properties/sourceVolumeType - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|configmaps - if: showConfigMapOrSecretName|configMap - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/init/properties/script/properties/configMap/properties/name - type: select - - allowUserDefinedOption: true - fetch: resourceNames|core|v1|secrets - if: showConfigMapOrSecretName|secret - label: - text: labels.script.volumeName - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/init/properties/script/properties/secret/properties/secretName - type: select - if: showScriptOrStashForm|script - type: single-step-form - - elements: - - label: - text: labels.restoreSession.snapshot - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/rules/properties/0/properties/snapshots/properties/0 - type: input - - discriminator: - repositoryChoise: - type: string + # standalone mode + - type: block-layout + label: Standalone + showLabels: true + if: + type: function + name: dbTypeEqualsTo|standalone + # schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone elements: - - label: - text: labels.repositories.title - type: label-element - - computed: setInitialRestoreSessionRepo - onChange: onInitRepositoryChoiseChange - options: - - text: options.createOrSelect.select.text - value: select - - text: options.createOrSelect.create.text - value: create - schema: - $ref: discriminator#/properties/repositoryChoise - type: radio - - allowUserDefinedOption: true - fetch: resourceNames|stash.appscode.com|v1alpha1|repositories - if: showRepositorySelectOrCreate|select - label: - text: labels.repositories.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/repository/properties/name - type: select - - alias: repository_create_init - chart: - name: uibytebuildersdev-component-repository-create - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRepositorySelectOrCreate|create - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRepository_init_repo/properties/spec/properties/backend - type: reusable-element - type: single-step-form - - if: returnFalse - label: - text: labels.backupConfiguration.targetReference.name - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/target/properties/ref/properties/name - type: input - - discriminator: - customizeRestoreJobRuntimeSettings: - type: string + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/compute/standalone/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|standalone + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|standalone + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|standalone + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/controlledResources + + # cluster mode + - type: block-layout + label: Cluster + showLabels: true + if: + type: function + name: dbTypeEqualsTo|cluster + # schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster elements: - - computed: initCustomizeRestoreJobRuntimeSettings - label: - isSubsection: true - text: labels.runtimeSettings.choise - onChange: onCustomizeRestoreJobRuntimeSettingsChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/customizeRestoreJobRuntimeSettings - type: radio - - alias: runtime_settings_init - chart: - name: uibytebuildersdev-component-runtime-settings - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - if: showRuntimeForm|yes - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/stashAppscodeComRestoreSession_init/properties/spec/properties/runtimeSettings - type: reusable-element - type: single-step-form - if: showScriptOrStashForm|stashBackup - type: single-step-form - - if: returnFalse - label: - text: labels.waitForInitialRestore - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/init/properties/waitForInitialRestore - type: switch - if: showInitializationForm - type: single-step-form - type: single-step-form - type: single-step-form - id: initialization - title: steps.3.label -- form: - discriminator: - repoInitialSelectionStatus: - type: string - scheduleBackup: - default: "yes" - type: string - elements: - - computed: initScheduleBackupForEdit - if: showScheduleBackup - label: - text: labels.backup.title - onChange: onScheduleBackupChange - options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/scheduleBackup - type: radio - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean - elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string - elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean - elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean - elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - if: showBackupForm - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.4.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/compute/cluster/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|cluster + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|cluster + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|cluster + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/controlledResources + + # sentinel mode + - type: block-layout + label: Sentinel + showLabels: true + if: + type: function + name: dbTypeEqualsTo|sentinel + # schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/compute/sentinel/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|sentinel + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|sentinel + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|sentinel + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComRedis/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean + - type: block-layout + showLabels: false elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComRedis/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: + - type: block-layout + showLabels: false + elements: + - type: block-layout + label: Cluster + showLabels: true elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComRedis/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComRedis/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - elements: - - elements: - - alias: pod_template_standalone - chart: - name: uibytebuildersdev-component-pod-template - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - functionCallbacks: - isEditWizard: - $ref: functions#/returnTrue - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/podTemplate - type: reusable-element - type: single-step-form - type: single-step-form - id: pod-template - title: steps.6.label -- form: - elements: - - alias: reusable_service_templates - chart: - name: uibytebuildersdev-component-service-templates - version: v0.27.0 - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/serviceTemplates - type: reusable-element - type: single-step-form - id: networking - title: steps.7.label -- form: - elements: - - elements: - - discriminator: - configuration: - type: string - configurationSource: - default: use-existing-config - type: string - elements: - - label: - text: labels.to_update_config - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - params: - cluster: - $ref: store#/route/params/cluster - dbname: - $ref: model#/metadata/release/name - domain: - $ref: store#/domain - group: - $ref: model#/metadata/resource/group - kind: - $ref: model#/metadata/resource/kind - namespace: - $ref: model#/metadata/release/namespace - owner: - $ref: store#/route/params/user - resource: - $ref: model#/metadata/resource/name - version: - $ref: model#/metadata/resource/version - path: ${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/redisopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=Reconfigure - - disabled: true - label: - text: labels.custom_config - onChange: onConfigurationSourceChange - options: - - text: options.configuration_source.use_existing_config.label - value: use-existing-config - - text: options.configuration_source.create_new_config.label - value: create-new-config - schema: - $ref: discriminator#/configurationSource - type: radio - - allowUserDefinedOption: true - disabled: true - fetch: getSecrets - if: isEqualToDiscriminatorPath|use-existing-config|/configurationSource - label: - text: labels.name - schema: - $ref: schema#/properties/resources/properties/kubedbComRedis/properties/spec/properties/configSecret/properties/name - type: select - type: single-step-form - type: single-step-form - type: single-step-form - id: custom-config - title: steps.8.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/storage/redis/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/redis/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/redis/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/redis/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/redis/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComRedis/spec/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/redis/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/redis/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/redis/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/redis/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/redis/properties/upperBound + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComRedis/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/compute/standalone/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string - elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|standalone - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|standalone - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|standalone - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone/properties/controlledResources - type: multiselect - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone - type: single-step-form - if: dbTypeEqualsTo|standalone - label: - text: Standalone - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone - show_label: true - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/compute/cluster/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string - elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|cluster - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|cluster - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|cluster - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster/properties/controlledResources - type: multiselect - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster - type: single-step-form - if: dbTypeEqualsTo|cluster - label: - text: Cluster - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster - show_label: true - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/compute/sentinel/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string - elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|sentinel - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|sentinel - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|sentinel - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel/properties/controlledResources - type: multiselect - label: - text: Sentinel - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/sentinel - show_label: true - type: single-step-form - if: dbTypeEqualsTo|sentinel - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: SelectNodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.9.label -- form: - discriminator: - dbDetails: - default: false - type: boolean - elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - computed: getDbDetails - if: returnFalse - type: input - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/storage/standalone/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/standalone/properties/trigger - type: select - - label: - text: Expansion Mode + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/standalone/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/standalone/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComRedis/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComRedis/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/standalone/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/standalone/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/standalone/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/standalone/properties/upperBound - type: input - if: dbTypeEqualsTo|standalone - label: - text: Standalone - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/standalone - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/storage/cluster/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/cluster/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/cluster/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/cluster/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/cluster/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/cluster/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: Scaling Rules - onChange: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/cluster/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/cluster/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/cluster/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/cluster/properties/upperBound - type: input - if: dbTypeEqualsTo|cluster - label: - text: Cluster - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/compute/properties/cluster - show_label: true - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/storage/sentinel/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/usageThreshold - type: input - - addFormLabel: Scaling Rules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/sentinel/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/sentinel/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/upperBound - type: input - label: - text: Sentinel - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComRedisAutoscaler/spec/storage/sentinel/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/scalingRules/items/properties/threshold + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComRedis/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/sentinel/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComRedisAutoscaler/spec/storage/sentinel/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel/properties/upperBound - type: input - label: - text: ConfigServer - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/storage/properties/sentinel - show_label: true - type: single-step-form - if: dbTypeEqualsTo|sentinel - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComRedisAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.10.label -- form: - discriminator: - binding: - default: false - type: boolean + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComRedis/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: binding + label: Gateway Binding elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -type: multi-step-form + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-redis-editor/ui/functions.js b/charts/kubedbcom-redis-editor/ui/functions.js index 25e7490fe0..23c8657f49 100644 --- a/charts/kubedbcom-redis-editor/ui/functions.js +++ b/charts/kubedbcom-redis-editor/ui/functions.js @@ -1,2886 +1,1476 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + initRepositoryChoiseForEdit() + + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } -} -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + function initScheduleBackup() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' + } -function isNotEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue !== value -} + function onScheduleBackupChange() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (scheduleBackup === 'no') { + // delete stashAppscodeComBackupConfiguration + commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + // delete annotation from kubedbComRedis annotation + deletekubedbComRedisAnnotation(getValue, model, commit) + } else { + const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + // create stashAppscodeComBackupConfiguration and initialize it if not exists - const resources = (resp && resp.data && resp.data.items) || [] + const dbName = getValue(model, '/metadata/release/name') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + if ( + !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && + !isBluePrint + ) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration', + value: stashAppscodeComBackupConfiguration, + }) + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + } + } } -} - -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function deletekubedbComRedisAnnotation(getValue, model, commit) { + const annotations = getValue(model, '/resources/kubedbComRedis/metadata/annotations') || {} + const filteredKeyList = + Object.keys(annotations).filter( + (k) => + k !== 'stash.appscode.com/backup-blueprint' && + k !== 'stash.appscode.com/schedule' && + !k.startsWith('params.stash.appscode.com/'), + ) || [] + const filteredAnnotations = {} + filteredKeyList.forEach((k) => { + filteredAnnotations[k] = annotations[k] + }) + commit('wizard/model$update', { + path: '/resources/kubedbComRedis/metadata/annotations', + value: filteredAnnotations, + }) + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + function getBackupConfigsAndAnnotations(getValue, model) { + const stashAppscodeComBackupConfiguration = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration', + ) + const kubedbComRedisAnnotations = + getValue(model, '/resources/kubedbComRedis/metadata/annotations') || {} - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const isBluePrint = Object.keys(kubedbComRedisAnnotations).some( + (k) => + k === 'stash.appscode.com/backup-blueprint' || + k === 'stash.appscode.com/schedule' || + k.startsWith('params.stash.appscode.com/'), + ) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return { + stashAppscodeComBackupConfiguration, + isBluePrint, + } } - return ans -} - -async function getRedisSentinels({ axios, storeGet, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/resources/kubedbComRedis/spec/sentinelRef/namespace') + // backup form + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false + } - watchDependency('model#/resources/kubedbComRedis/spec/sentinelRef/namespace') + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let namespaceList = [] + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComRedis') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - if (owner && cluster && namespace) { + // get values.yaml to populate data when backup-config is being created try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redissentinels`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version - const resources = (resp && resp.data && resp.data.items) || [] + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - return resources - } catch (err) { - console.log(err) - return [] + const resp = await axios.get(url) + + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} + } catch (e) { + console.log(e) } - } else { - return [] - } -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + // check config with metadata name first + let config = configs?.find( + (item) => + item.metadata?.name === name && + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - return ans -} + // set backup switch here + isBackupOn = !!config -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions } - }) -} - -function returnTrue() { - return true -} -function returnStringYes() { - return 'yes' -} - -function hasSentinelObject({ model, getValue }) { - const sentinelObj = getValue(model, '/resources/kubedbComRedisSentinel_sentinel') + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } - return !!sentinelObj -} + setDiscriminatorValue('isBackupDataLoaded', true) + } -// ************************* Basic Info ********************************************** -async function getRedisVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') + } - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + function setBackupType() { + return 'BackupConfig' } - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + function getTypes() { + const arr = [ { - params: queryParams, + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - // keep only non deprecated versions - const filteredRedisVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] - filteredRedisVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredRedisVersions - } catch (e) { - console.log(e) - return [] + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) + } + return arr } -} -function onVersionChange({ model, getValue, commit }) { - const version = getValue(model, '/resources/kubedbComRedis/spec/version') - - if (hasSentinelObject({ model, getValue })) { + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') commit('wizard/model$update', { - path: '/resources/kubedbComRedisSentinel_sentinel/spec/version', - value: version, + path: '/backupType', + value: type, force: true, }) - } -} - -let storageClassList = [] -function ondeletionPolicyChange({ model, getValue, commit }) { - const deletionPolicy = getValue(model, '/resources/kubedbComRedis/spec/deletionPolicy') - - if (hasSentinelObject({ model, getValue })) { + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), + force: true, + }) + } + commit('wizard/model$delete', '/context') commit('wizard/model$update', { - path: '/resources/kubedbComRedisSentinel_sentinel/spec/deletionPolicy', - value: deletionPolicy, + path: '/resources/kubedbComRedis', + value: objectCopy(dbResource), force: true, }) } - setStorageClass({ model, getValue, commit }) -} + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') -// ************************* Auth Secret Field ****************************************** -function showAuthPasswordField({ model, getValue, watchDependency }) { - watchDependency('model#/resources') - const modelPathValue = getValue(model, '/resources') - return !!( - modelPathValue && - modelPathValue.secret && - modelPathValue.secret.metadata && - modelPathValue.secret.metadata.name && - !showAuthSecretField({ model, getValue, watchDependency }) - ) -} + return selectedType === type + } -function showAuthSecretField({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComRedis/spec') - const modelPathValue = getValue(model, '/resources/kubedbComRedis/spec') - return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) -} + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations -function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { - const resp = - !showAuthSecretField({ model, getValue, watchDependency }) && - !showAuthPasswordField({ model, getValue, watchDependency }) - const secret = getValue(model, '/resources/secret_auth') - if (resp && !secret) { - commit('wizard/model$update', { - path: '/resources/secret_auth', - value: { - data: { - password: '', - }, - }, - force: true, - }) + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) } - return resp -} -// ********************* Database Mode *********************** -function setDatabaseMode({ model, getValue }) { - const mode = getValue(model, '/resources/kubedbComRedis/spec/mode') + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') + if (blueprintSwitch) addLabelAnnotation('annotations') + else deleteLabelAnnotation('annotations') + } - return mode || 'Standalone' -} + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver + } -async function getStorageClassNames({ axios, storeGet, commit, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComRedis/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) + } else { + commit('wizard/model$delete', path) + } + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) + function addLabelAnnotation(type) { + const obj = objectCopy(initialDbMetadata[type]) - const resources = (resp && resp.data && resp.data.items) || [] + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` + } else { + obj['kubedb.com/archiver'] = 'true' + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) + commit('wizard/model$update', { + path: `/resources/kubedbComRedis/metadata/${type}`, + value: obj, + force: true, + }) + } - storageClassList = resources - const initialStorageClass = getValue( - model, - '/resources/kubedbComRedis/spec/storage/storageClassName', - ) - if (!initialStorageClass) setStorageClass({ model, getValue, commit }) - return resources -} + function deleteLabelAnnotation(type) { + const obj = initialDbMetadata[type] -function setStorageClass({ model, getValue, commit }) { - const deletionPolicy = getValue(model, '/resources/kubedbComRedis/spec/deletionPolicy') || '' - let storageClass = - getValue(model, '/resources/kubedbComRedis/spec/storage/storageClassName') || '' - const suffix = '-retain' + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + commit('wizard/model$update', { + path: `/resources/kubedbComRedis/metadata/${type}`, + value: obj, + force: true, + }) + } - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') + commit('wizard/model$update', { + path: '/context', + value: context, + force: true, + }) + if (context === 'Create') { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, + force: true, + }) + } + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) + } - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } + const list = filteredList?.map((ele) => ele.metadata.name) + return list } - if (storageClass) { + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) + commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/storage/storageClassName', - value: storageClass, + path: '/resources/coreKubestashComBackupConfiguration', + value: configDetails, force: true, }) } -} -function deleteDatabaseModePath({ getValue, commit, model }) { - const mode = getValue(model, '/resources/kubedbComRedis/spec/mode') - if (mode === 'Cluster') { - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/sentinelRef') - commit('wizard/model$delete', '/resources/kubedbComRedisSentinel_sentinel') - } else if (mode === 'Standalone') { - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/sentinelRef') - commit('wizard/model$delete', '/resources/kubedbComRedisSentinel_sentinel') + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' } -} -function isEqualToDatabaseMode({ getValue, watchDependency, model }, value) { - watchDependency('model#/activeDatabaseMode') - const mode = getValue(model, '/activeDatabaseMode') - return mode === value -} - -function showSentinelNameAndNamespace({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/createSentinel') - const verd = getValue(discriminator, '/createSentinel') + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' + } - return !verd -} + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName + } -function onCreateSentinelChange({ discriminator, getValue, commit, model }) { - const verd = getValue(discriminator, '/createSentinel') + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } - if (verd === true) { - const sentinelObj = getValue(model, '/resources/kubedbComRedisSentinel_sentinel') + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' + } - if (!sentinelObj) { - const redisSpec = getValue(model, '/resources/kubedbComRedis/spec') + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - const { version, tls, storage, monitor, deletionPolicy } = redisSpec || {} + return repoInitialSelectionStatus + } + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value commit('wizard/model$update', { - path: '/resources/kubedbComRedisSentinel_sentinel/spec', - value: { - version, - tls, - storage, - monitor, - deletionPolicy, + path: modelPath, + value: session, + }) + } + } + + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComRedis/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'RedisBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, }, + }, + } + + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComRedisBinding', + value: bindingValues, force: true, }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComRedisBinding') } - } else if (verd === false) { - commit('wizard/model$delete', '/resources/kubedbComRedisSentinel_sentinel') } -} -function setCreateSentinel({ model, getValue }) { - const sentinelObj = getValue(model, '/resources/kubedbComRedisSentinel_sentinel') + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComRedisBinding') + return isExposeBinding + } - return !!sentinelObj -} -// ************************** TLS ******************************88 + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } -function setApiGroup() { - return 'cert-manager.io' -} + /********** Compute Autoscaling ***********/ -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComRedis/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComRedis/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComRedis/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComRedis/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') + let autoscaleType = '' + let dbDetails = {} - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' - if (!url) return [] + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') || + '' - try { - const resp = await axios.get(url) + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises/${name}`, + ) + dbDetails = resp.data || {} - const resources = (resp && resp.data && resp.data.items) || [] + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -function onIssuerRefChange({ model, getValue, commit }) { - const issuerRef = getValue(model, '/resources/kubedbComRedis/spec/tls/issuerRef') - - if (hasSentinelObject({ model, getValue })) { commit('wizard/model$update', { - path: '/resources/kubedbComRedisSentinel_sentinel/spec/tls/issuerRef', - value: issuerRef, + path: `/metadata/release/namespace`, + value: namespace, force: true, }) - } -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComRedis/spec/sslMode') - return val || 'require' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/tls', - value: { issuerRef: {}, certificates: [] }, + path: `/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name`, + value: name, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/monitor', - value: {}, + path: `/resources/autoscalingKubedbComRedisAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/monitor') } - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} + function isKubedb() { + return !!storeGet('/route/params/actions') + } -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} + function isConsole() { + const isKube = isKubedb() -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/monitor/prometheus/exporter') + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComRedisAutoscaler/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComRedisAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } + } + + return !isKube } -} -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} + const resources = (resp && resp.data && resp.data.items) || [] -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComRedis/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComRedis/spec/init/script') + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { + function onNamespaceChange() { + const namespace = getValue(model, '/metadata/release/namespace') + const agent = getValue(model, '/resources/kubedbComRedis/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, + path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + value: [namespace], force: true, }) + } + } + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, + path: '/resources/autoscalingKubedbComRedisAutoscaler/metadata/name', + value: modifiedName, force: true, }) + + // delete the other type object from vuex wizard model + if (type === 'compute') + commit('wizard/model$delete', '/resources/autoscalingKubedbComRedisAutoscaler/spec/storage') + if (type === 'storage') + commit('wizard/model$delete', '/resources/autoscalingKubedbComRedisAutoscaler/spec/compute') + } + + async function fetchTopologyMachines() { + const instance = hasAnnotations() + + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) + + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } } } -} -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComRedis/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} + function hasAnnotations() { + const annotations = + getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') + return !!instance + } - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) + function setAllowedMachine(minmax) { + const annotations = + getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + const mx = instance?.includes(',') ? instance.split(',')[1] : '' + const mn = instance?.includes(',') ? instance.split(',')[0] : '' - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') + if (minmax === 'min') return mn + else return mx + } - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComRedis/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/init/script') + async function getMachines(minmax) { + // watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${depends}` - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') + // watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) + + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) + + return dependantIndex === -1 ? machines : filteredMachine } -} -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComRedis/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComRedis/spec/init/script/secret/secretName') + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComRedisAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) || {} + const instance = annotations['kubernetes.io/instance-type'] - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} + const minMachine = getValue(discriminator, '/allowedMachine-min') + const maxMachine = getValue(discriminator, '/allowedMachine-max') + const minMaxMachine = `${minMachine},${maxMachine}` + annotations['kubernetes.io/instance-type'] = minMaxMachine -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/init/script/secret') + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComRedisAutoscaler/spec/compute/${type}` - if (!valueExists(model, getValue, '/resources/kubedbComRedis/spec/init/script/configMap')) { + if (minMachine && maxMachine && instance !== minMaxMachine) { commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/init/script/configMap', - value: { - name: '', - }, + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComRedis/spec/init/script/secret')) { commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/init/script/secret', - value: { - secretName: '', - }, + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: { ...annotations }, + force: true, }) } } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} + function hasNoAnnotations() { + return !hasAnnotations() + } -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComRedisAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, + }) + return list + } -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] + } - return repositoryChoise === value -} + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComRedisAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( + model, + '/resources/autoscalingKubedbComRedisAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length + } -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency('model#/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') && + !!getValue(discriminator, '/autoscalingType') + ) + } - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) + function setApplyToIfReady() { + return 'IfReady' } -} -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} + function dbTypeEqualsTo(type) { + // watchDependency('discriminator#/dbDetails') -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} + const { spec } = dbDetails || {} + const { cluster, sentinelRef } = spec || {} + let verd = '' + if (cluster) verd = 'cluster' + else { + if (sentinelRef) verd = 'sentinel' + else verd = 'standalone' + } + clearSpecModel(verd) + return type === verd && spec + } -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', + function clearSpecModel(dbtype) { + if (dbtype === 'standalone') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/cluster`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/sentinel`, + ) + } else if (dbtype === 'cluster') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/standalone`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/sentinel`, + ) + } else if (dbtype === 'sentinel') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/standalone`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/cluster`, ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) } } -} -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } } } -} -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) + const resources = (resp && resp.data && resp.data.items) || [] - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] } - }) -} + } -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -// FOR Backup Configuration + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -// schedule bakcup + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComRedisAnnotations = - getValue(model, '/resources/kubedbComRedis/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComRedisAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - return { - stashAppscodeComBackupConfiguration, - isBluePrint, + return ans } -} - -function deletekubedbComRedisAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComRedis/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/metadata/annotations', - value: filteredAnnotations, - }) -} -function addkubedbComRedisAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComRedis/metadata/annotations') || {} + function hasSentinelObject() { + const sentinelObj = getValue(model, '/resources/kubedbComRedisSentinel_sentinel') - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value + return !!sentinelObj } - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/metadata/annotations', - value: annotations, - force: true, - }) -} + /****** Monitoring *********/ -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComRedis/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComRedis/spec/monitor') + } - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', + force: true, + }) + } -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComRedis/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComRedis/spec/monitor/prometheus/exporter') + } + } -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComRedis annotation - deletekubedbComRedisAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) + // function onNamespaceChange() { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComRedis/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } - // create stashAppscodeComBackupConfiguration and initialize it if not exists + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComRedis/spec/metadata/labels') - const dbName = getValue(model, '/metadata/release/name') + const agent = getValue(model, '/resources/kubedbComRedis/spec/monitor/agent') - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, force: true, }) } } -} -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComRedis/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) - if (scheduleBackup === 'yes') return true - else return false -} + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -async function initBackupData({ storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComRedis') - initialDbMetadata = objectCopy(dbResource.metadata) - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) + if (hasSentinelObject()) { + commit('wizard/model$update', { + path: '/resources/kubedbComRedisSentinel_sentinel/spec/monitor/agent', + value: agent, + force: true, + }) + } + } - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` + + const isKube = !!storeGet('/route/params/actions') + + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/redisopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } + + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } + } - // set backup switch here - isBackupOn = !!config + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } + } - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, + }) - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions - } + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - setDiscriminatorValue('isBackupDataLoaded', true) -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComRedis/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -async function setBackupType() { - return 'BackupConfig' -} + if (!configMapName) return [] -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - return arr -} - -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), - force: true, - }) - } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComRedis', - value: objectCopy(dbResource), - force: true, - }) -} - -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') - - return selectedType === type -} - -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations - - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} - -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} - -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} - -function onArchiverChange({ getValue, discriminator, commit }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComRedis/spec/archiver' - if (archiverSwitch) { - commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, - }) - } else { - commit('wizard/model$delete', path) - } -} - -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) - - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' - } - - commit('wizard/model$update', { - path: `/resources/kubedbComRedis/metadata/${type}`, - value: obj, - force: true, - }) -} - -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] - - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] - - commit('wizard/model$update', { - path: `/resources/kubedbComRedis/metadata/${type}`, - value: obj, - force: true, - }) -} - -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} - -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, - force: true, - }) - } -} - -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} - -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} - -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} - -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} - -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} - -function getNamespaceArray() { - return namespaceList -} - -// invoker form -function initBackupInvoker() { - return 'backupConfiguration' -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model, storeGet }) { - const kind = storeGet('/resource/layout/result/resource/kind') - const backupInvoker = getValue(discriminator, '/backupInvoker') - const annotations = getValue(model, '/resources/kubedbComRedis/metadata/annotations') - - // get name namespace labels to set in db resource when backup is not enabled initially - - if (backupInvoker === 'backupConfiguration') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: initialModel, - force: true, - }) - - if ( - !dbResource.metadata?.annotations?.['blueprint.kubestash.com/name'] && - !dbResource.metadata?.annotations?.['blueprint.kubestash.com/namespace'] - ) { - delete annotations['blueprint.kubestash.com/name'] - delete annotations['blueprint.kubestash.com/namespace'] - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/metadata/annotations', - value: annotations, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - if (!isBackupOn) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } - annotations['blueprint.kubestash.com/name'] = `${kind.toLowerCase()}-blueprint` - annotations['blueprint.kubestash.com/namespace'] = 'kubedb' - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/metadata/annotations', - value: annotations, - force: true, - }) - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) - return repoInitialSelectionStatus -} + const configMaps = (resp && resp.data && resp.data.data) || {} -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) + return configMapKeys + } catch (e) { + console.log(e) + return [] } } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComRedis/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addkubedbComRedisAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addkubedbComRedisAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComRedis/metadata/annotations') || {} - const newAnnotations = {} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComRedis/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComRedis/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComRedis/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComRedis/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComRedis/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') + const secrets = (resp && resp.data && resp.data.items) || [] - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) }) - } - } - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] } } - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComRedis/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } - - if (hasSentinelObject({ model, getValue })) { - commit('wizard/model$update', { - path: '/resources/kubedbComRedisSentinel_sentinel/spec/monitor/agent', - value: agent, - force: true, - }) - } -} - -function onServiceMonitorChange({ model, getValue, commit }) { - const serviceMonitor = getValue( - model, - '/resources/kubedbComRedis/spec/monitor/prometheus/serviceMonitor', - ) - - if (hasSentinelObject({ model, getValue })) { - commit('wizard/model$update', { - path: '/resources/kubedbComRedisSentinel_sentinel/spec/monitor/prometheus/serviceMonitor', - value: serviceMonitor, - force: true, - }) - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComRedis/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - - if (stringPassword) { - commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), - force: true, - }) - commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComRedis/spec/init/initialized') - watchDependency('model#/resources/kubedbComRedis/spec/init/initialized') - return !!initialized -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComRedis/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', ) - const secrets = (resp && resp.data && resp.data.items) || [] + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + if (!secretName) return [] - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] - } -} - -//////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/redis.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComRedis/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/redis.conf') -} - -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/redis.conf') - return atob(value) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComRedis/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - } -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/redisopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} - -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} - -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} - -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) - } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` + const secret = (resp && resp.data && resp.data.data) || {} - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} - -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data - } - } catch (e) { - console.log(e) - } - return [] -} - -function initBlueprint() { - return 'create' -} - -function initUsagePolicy() { - return 'Same' -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} - -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} - -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) - - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComRedisAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComRedisAutoscaler/metadata/namespace', - value: namespace, - force: true, - }) - } - } - - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComRedisAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComRedisAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises/${name}`, - ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) + return secretKeys } catch (e) { console.log(e) + return [] } } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComRedisAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ axios, storeGet, watchDependency, model, getValue, commit }, type) { - watchDependency('discriminator#/dbDetails') - - const { spec } = dbDetails || {} - const { cluster, sentinelRef } = spec || {} - let verd = '' - if (cluster) verd = 'cluster' - else { - if (sentinelRef) verd = 'sentinel' - else verd = 'standalone' - } - clearSpecModel({ commit }, verd) - return type === verd && spec -} - -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComRedisAutoscaler/spec/${autoscaleType}/cluster`, - ) - } -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComRedisAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) - - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComRedisAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComRedisAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComRedisAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name', - ) + function returnFalse() { + return false } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + /********** Binding ***********/ -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComRedisBinding') + return isExposeBinding } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComRedisAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComRedisAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComRedisAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} - -function setApplyToIfReady() { - return 'IfReady' -} -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComRedis/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'RedisBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, } - } else { - if (!isNaN(value)) { - value += 'Gi' + + if (value) { commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, + path: '/resources/catalogAppscodeComRedisBinding', + value: bindingValues, force: true, }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComRedisBinding') } } -} - -function objectCopy(obj) { - const temp = JSON.stringify(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 labels = getValue(model, '/resources/kubedbComRedis/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'RedisBinding', - metadata: { - labels, - 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') - } -} -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComRedisAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) - - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] - } + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value } -} - -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComRedisAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - console.log(machines) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }, type) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComRedisAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComRedisAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComRedisAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + return { + initScheduleBackup, + initScheduleBackupForEdit, + onScheduleBackupChange, + showBackupForm, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + onBackupTypeChange, + isBackupType, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showConfigList, + showSchedule, + showScheduleBackup, + getDefaultSchedule, + onInputChangeSchedule, + + getDbDetails, + isKubedb, + isConsole, + getNamespaces, + isRancherManaged, + onNamespaceChange, + initMetadata, + fetchTopologyMachines, + setTrigger, + hasAnnotations, + setAllowedMachine, + getMachines, + onMachineChange, + hasNoAnnotations, + setControlledResources, + fetchNodeTopology, + isNodeTopologySelected, + showOpsRequestOptions, + setApplyToIfReady, + dbTypeEqualsTo, + handleUnit, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + + isBindingAlreadyOn, + addOrRemoveBinding, + + setValueFromDbDetails, } } - -return { - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - isNotEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getRedisSentinels, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - hasSentinelObject, - getRedisVersions, - onVersionChange, - ondeletionPolicyChange, - showAuthPasswordField, - showAuthSecretField, - showNewSecretCreateField, - showSentinelNameAndNamespace, - onCreateSentinelChange, - setCreateSentinel, - setDatabaseMode, - getStorageClassNames, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - onIssuerRefChange, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deletekubedbComRedisAnnotation, - addkubedbComRedisAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - onServiceMonitorChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - disableInitializationSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfiguration, - setConfigurationFiles, - onSetCustomConfigChange, - getOpsRequestUrl, - getCreateNameSpaceUrl, - setStorageClass, - - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, - getNamespaceArray, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, -} diff --git a/charts/kubedbcom-singlestore-editor-options/ui/create-ui.yaml b/charts/kubedbcom-singlestore-editor-options/ui/create-ui.yaml index 543652568e..3c5fe40bba 100644 --- a/charts/kubedbcom-singlestore-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-singlestore-editor-options/ui/create-ui.yaml @@ -1,407 +1,420 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Singlestore/versions - if: isToggleOn|databases/Singlestore/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Singlestore/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - if: + type: function + name: returnFalse + init: + type: func + value: initBundle + label: '' + type: label-element + - disableUnselect: true + loader: getAdminOptions|databases/Singlestore/versions + if: + type: function + name: isToggleOn|databases/Singlestore/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Singlestore/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Singlestore/mode + loader: getAdminOptions|databases/Singlestore/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/Singlestore/mode + label: Database Mode + watcher: + func: toggleTls + paths: + - schema/properties/spec/properties/mode + schema: schema/properties/spec/properties/mode + type: radio + - elements: + - label: Storage Size + schema: schema/properties/spec/properties/topology/properties/aggregator/properties/persistence/properties/size + type: input + - init: + type: func + value: setReplicaNumber + label: Replica number + schema: schema/properties/spec/properties/topology/properties/aggregator/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/aggregator/properties/podResources/properties/machine type: select - - computed: getDefault|databases/Singlestore/mode - fetch: getAdminOptions|databases/Singlestore/mode - hasDescription: true - if: isToggleOn|databases/Singlestore/mode - label: - text: labels.database.mode - onChange: toggleTls - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/aggregator/properties/persistence/properties/size - type: input - - computed: setReplicaNumber - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/aggregator/properties/replicas - type: input - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/aggregator/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/aggregator - disabled: isMachineNotCustom|topology/aggregator - if: isMachineCustom|topology/aggregator - label: - text: labels.cpu - onChange: setRequests|cpu|topology/aggregator - schema: - $ref: schema#/properties/spec/properties/topology/properties/aggregator/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/aggregator - disabled: isMachineNotCustom|topology/aggregator - if: isMachineCustom|topology/aggregator - label: - text: labels.cpu - onChange: setRequests|memory|topology/aggregator - schema: - $ref: schema#/properties/spec/properties/topology/properties/aggregator/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - if: isEqualToModelPathValue|Topology|/spec/mode - label: - text: Aggregator - show_label: true - type: single-step-form - - elements: - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/leaf/properties/persistence/properties/size - type: input - - computed: setReplicaNumber - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/leaf/properties/replicas - type: input - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/leaf/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/leaf - disabled: isMachineNotCustom|topology/leaf - if: isMachineCustom|topology/leaf - label: - text: labels.cpu - onChange: setRequests|cpu|topology/leaf - schema: - $ref: schema#/properties/spec/properties/topology/properties/leaf/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/leaf - disabled: isMachineNotCustom|topology/leaf - if: isMachineCustom|topology/leaf - label: - text: labels.memory - onChange: setRequests|memory|topology/leaf - schema: - $ref: schema#/properties/spec/properties/topology/properties/leaf/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - if: isEqualToModelPathValue|Topology|/spec/mode - label: - text: Leaf - show_label: true - type: single-step-form + - init: + type: func + value: setLimits|cpu|topology/aggregator + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom|topology/aggregator + label: CPU + watcher: + func: setRequests|cpu|topology/aggregator + paths: + - schema/properties/spec/properties/topology/properties/aggregator/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/aggregator/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/aggregator + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom|topology/aggregator + label: Memory + watcher: + func: setRequests|memory|topology/aggregator + paths: + - schema/properties/spec/properties/topology/properties/aggregator/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/aggregator/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Aggregator + showLabels: true + type: block-layout + - elements: + - label: Storage Size + schema: schema/properties/spec/properties/topology/properties/leaf/properties/persistence/properties/size + type: input + - init: + type: func + value: setReplicaNumber + label: Replica number + schema: schema/properties/spec/properties/topology/properties/leaf/properties/replicas + type: input + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/leaf/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/leaf + disable: isMachineNotCustom|topology/leaf + if: + type: function + name: isMachineCustom|topology/leaf + label: CPU + watcher: + func: setRequests|cpu|topology/leaf + paths: + - schema/properties/spec/properties/topology/properties/leaf/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/leaf/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory|topology/leaf + disable: isMachineNotCustom|topology/leaf + if: + type: function + name: isMachineCustom|topology/leaf + label: Memory + watcher: + func: setRequests|memory|topology/leaf + paths: + - schema/properties/spec/properties/topology/properties/leaf/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/leaf/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Leaf + showLabels: true + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + customClass: mt-10 + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + if: + type: function + name: isEqualToModelPathValue|Standalone|/spec/mode + label: Machine Profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage Class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: isEqualToModelPathValue|Standalone|/spec/mode + label: Storage Size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - loader: getSecrets + label: License Secret + refresh: true + schema: schema/properties/spec/properties/licenseSecret/properties/name + type: select + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - customClass: mt-10 - fetch: getMachineListForOptions - label: - text: labels.machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - if: isEqualToModelPathValue|Standalone|/spec/mode - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - if: isToggleOn|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + hideBlock: true + label: Labels & Annotations + showLabels: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name type: select - - if: isEqualToModelPathValue|Standalone|/spec/mode - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - fetch: getSecrets - label: - text: labels.licenseSecret - refresh: true - schema: - $ref: schema#/properties/spec/properties/licenseSecret/properties/name + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + options: + - description: shared + text: Shared + value: Shared + - description: Dedicated + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default type: select - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + hideBlock: true + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - discriminator: - backup: - default: false - type: boolean - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup - type: switch - - elements: - - computed: toggleTls - label: - text: Enable TLS? - schema: - $ref: schema#/properties/spec/properties/admin/properties/tls/properties/default - type: switch - - fetch: getAdminOptions|clusterIssuers - if: showIssuer - label: - text: labels.clusterIssuers - required: true - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterIssuers/properties/default - type: select - if: isEqualToModelPathValue|Topology|/spec/mode - type: single-step-form - - if: isToggleOn|expose - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - init: + type: func + value: toggleTls + label: Enable TLS? + schema: schema/properties/spec/properties/admin/properties/tls/properties/default type: switch - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + - loader: getAdminOptions|clusterIssuers + if: + type: function + name: showIssuer + label: Cluster Issuers + validation: + type: required + schema: schema/properties/spec/properties/admin/properties/clusterIssuers/properties/default + type: select + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + type: block-layout + - if: + type: function + name: isToggleOn|expose + label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default + type: switch + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-singlestore-editor-options/ui/functions.js b/charts/kubedbcom-singlestore-editor-options/ui/functions.js index 05671774a1..0761230ba5 100644 --- a/charts/kubedbcom-singlestore-editor-options/ui/functions.js +++ b/charts/kubedbcom-singlestore-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,1063 +317,1079 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('monitoring', false) + setDiscriminatorValue('backup', false) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function clearArbiterHidden() { + commit('wizard/model$update', { + path: `/spec/arbiter/enabled`, + value: false, + force: true, + }) - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + commit('wizard/model$update', { + path: `/spec/hidden/enabled`, + value: false, + force: true, + }) + } - const resources = (resp && resp.data && resp.data.items) || [] + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } + } + + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } -async function getMySqlVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - const resources = (resp && resp.data && resp.data.items) || [] + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } - // keep only non deprecated versions - const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - filteredMySqlVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMySqlVersions -} + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } + } -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } + + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } + }) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array + } - if (owner && cluster && namespace) { + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, { - params: { - filter: { - items: { - data: { username: null, password: null }, - metadata: { name: null }, - type: null, + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, }, - }, + ], }, }, ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] + } - const secrets = (resp && resp.data && resp.data.items) || [] + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } - const filteredSecrets = secrets.filter((item) => { - const validType = [ - 'kubernetes.io/service-account-token', - 'Opaque', - 'kubernetes.io/basic-auth', - ] - return validType.includes(item.type) - }) + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) }) - return filteredSecrets } catch (e) { console.log(e) } + return options } - return [] -} - -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } - }) - .filter((val) => !!val) - } - return array -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} - -function setReplicaNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 2 - } else return 1 -} -function setRouterNumber({ model, getValue }) { - const modelPathValue = getValue(model, '/spec/mode') - if (modelPathValue === 'Topology') { - return 3 - } else return 1 -} + const resources = (resp && resp.data && resp.data.items) || [] -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + if (owner && cluster && namespace) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { + items: { + data: { username: null, password: null }, + metadata: { name: null }, + type: null, + }, + }, + }, + }, + ) -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const secrets = (resp && resp.data && resp.data.items) || [] - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + const filteredSecrets = secrets.filter((item) => { + const validType = [ + 'kubernetes.io/service-account-token', + 'Opaque', + 'kubernetes.io/basic-auth', + ] + return validType.includes(item.type) + }) -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + } + } + return [] + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true + } -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] - } + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, }) - url = url.slice(0, -1) } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val } catch (e) { console.log(e) - return [] } - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} -function setStorageClass({ model, getValue, commit, discriminator, watchDependency }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - - const isChangeable = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'storageClasses', - ) - if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} - -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, discriminator, watchDependency }, 'alert') - ) -} -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} - -function clearArbiterHidden({ commit }) { - commit('wizard/model$update', { - path: `/spec/arbiter/enabled`, - value: false, - force: true, - }) - - commit('wizard/model$update', { - path: `/spec/hidden/enabled`, - value: false, - force: true, - }) -} + if (!getValue(model, `/spec/admin/databases/Singlestore/mode/toggle`)) { + let defMode = getDefault('databases/Singlestore/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Singlestore/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) + } -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/expose/default', + value: false, force: true, }) } - } catch (e) { - console.log(e) + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } + + setDiscriminatorValue('/bundleApiLoaded', true) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } - if (!getValue(model, `/spec/admin/databases/Singlestore/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Singlestore/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Singlestore/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' } - if (!features.includes('monitoring')) { + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } + + function notEqualToDatabaseMode(mode) { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + return modelPathValue && modelPathValue !== mode + } + + function onAuthChange() { commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', + path: '/spec/authSecret/name', value: '', force: true, }) commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', + path: '/spec/authSecret/password', + value: '', force: true, }) } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) + + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') commit('wizard/model$update', { path: '/spec/backup/tool', - value: '', + value: isBackupOn ? 'KubeStash' : '', force: true, }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} - -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` + function onReferSecretChange() { commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/authSecret/name', + value: '', force: true, }) } - return returnArray -} + function returnFalse() { + return false + } -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } - const options = getValue(model, `/spec/admin/${type}/available`) || [] + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } + } - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory + } else { + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu + } } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent } - const backupVal = getValue(model, '/spec/backup/tool') - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + function setReplicaNumber() { + const modelPathValue = getValue(model, '/spec/mode') + if (modelPathValue === 'Topology') { + return 2 + } else return 1 } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + commit('wizard/model$update', { + path: commitPath, + value: val, + force: true, + }) + } + + function setRouterNumber() { + const modelPathValue = getValue(model, '/spec/mode') + if (modelPathValue === 'Topology') { + return 3 + } else return 1 + } + + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' + + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } + + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: '/spec/admin/storageClasses/default', + value: storageClass, force: true, }) } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + function showArbiter() { + // watchDependency('model#/spec/arbiter/enabled') + const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isArbiterOn && notStandalone + } - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function showAuthSecretField() { + return !showAuthPasswordField() + } - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - ) - }) - } else return filteredlist -} + function showHidden() { + // watchDependency('model#/spec/hidden/enabled') + const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' + const notStandalone = notEqualToDatabaseMode('Standalone') + return isHiddenOn && notStandalone + } -function returnFalse() { - return false -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = [] - return !validType.includes(modelPathValue) -} -function showHidden({ watchDependency, model, getValue }) { - watchDependency('model#/spec/hidden/enabled') - const isHiddenOn = getValue(model, '/spec/hidden/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isHiddenOn && notStandalone -} -function notEqualToDatabaseMode({ model, getValue, watchDependency }, mode) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - return modelPathValue && modelPathValue !== mode -} -function showArbiter({ watchDependency, model, getValue }) { - watchDependency('model#/spec/arbiter/enabled') - const isArbiterOn = getValue(model, '/spec/arbiter/enabled') || '' - const notStandalone = notEqualToDatabaseMode({ model, getValue, watchDependency }, 'Standalone') - return isArbiterOn && notStandalone -} -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (val === 'capz' && ifDedicated()) return true } -} - -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, discriminator, watchDependency }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = [] + return !validType.includes(modelPathValue) + } -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory - } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue - } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory - } + function toggleTls() { + let modelPathValue = getValue(model, '/spec/mode') + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: modelPathValue !== 'Standalone', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/admin/tls/toggle', + value: modelPathValue !== 'Standalone', + force: true, + }) } - if (resource === 'memory') { + function updateAgentValue(val) { commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', force: true, }) + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: memory, + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', force: true, }) - return memory - } else { + } + + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/form/alert/enabled', + value: alert, force: true, }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/spec/admin/monitoring/agent', + value: agent, force: true, }) - return cpu } -} -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -function toggleTls({ commit, model, getValue, watchDependency }) { - let modelPathValue = getValue(model, '/spec/mode') - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: modelPathValue !== 'Standalone', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/admin/tls/toggle', - value: modelPathValue !== 'Standalone', - force: true, - }) -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + return returnArray + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + const options = getValue(model, `/spec/admin/${type}/available`) || [] + + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + let backupToolInitialValue = '' + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + if (type === 'backup') { + if (backupToolInitialValue === '') { + backupToolInitialValue = + features.includes('backup') && backupVal === 'KubeStash' && val ? 'on' : 'off' + return features.includes('backup') && backupVal === 'KubeStash' && val + } else { + if (backupToolInitialValue === 'on') { + return true + } else { + return false + } + } + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } + } + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + async function getMySqlVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, + }, + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + const resources = (resp && resp.data && resp.data.items) || [] -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + // keep only non deprecated versions + const filteredMySqlVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + + filteredMySqlVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMySqlVersions + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - setLimits, - setRequests, - toggleTls, - getNamespaces, - updateAlertValue, - getAdminOptions, - isToggleOn, - showAlerts, - getNodeTopology, - clearArbiterHidden, - returnFalse, - showHidden, - isConfigDatabaseOn, - notEqualToDatabaseMode, - filterNodeTopology, - onAuthChange, - setMonitoring, - isMachineNotCustom, - isMachineCustom, - showIssuer, - showArbiter, - clearConfiguration, - showStorageSizeField, - onBackupSwitch, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - getResources, - getMySqlVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - setReplicaNumber, - setRouterNumber, - setBackup, - showAdditionalSettings, - getDefault, + return { + clearArbiterHidden, + clearConfiguration, + dedicatedOnChange, + fetchJsons, + filterNodeTopology, + getCreateNameSpaceUrl, + getDefault, + getDefaultValue, + getMachineListForOptions, + getNamespaces, + getReferSecrets, + getResources, + getSecrets, + getSKU, + getZones, + ifCapiProviderIsNotEmpty, + ifDedicated, + ifZones, + initBundle, + isConfigAvailable, + isConfigDatabaseOn, + isEqualToModelPathValue, + isMachineCustom, + isMachineNotCustom, + isRancherManaged, + isVariantAvailable, + notEqualToDatabaseMode, + onAuthChange, + onBackupSwitch, + onCreateAuthSecretChange, + onReferSecretChange, + returnFalse, + setBackup, + setLimits, + setMachineToCustom, + setMonitoring, + setReplicaNumber, + setRequests, + setRouterNumber, + setStorageClass, + showAdditionalSettings, + showAlerts, + showArbiter, + showAuthPasswordField, + showAuthSecretField, + showHidden, + showIssuer, + showMultiselectZone, + showReferSecret, + showReferSecretSwitch, + showSecretDropdown, + showSelectZone, + showStorageSizeField, + toggleTls, + updateAgentValue, + updateAlertValue, + zonesOnChange, + fetchOptions, + getAdminOptions, + getNodeTopology, + checkIfFeatureOn, + isToggleOn, + getMySqlVersions, + } } diff --git a/charts/kubedbcom-singlestore-editor/ui/edit-ui.yaml b/charts/kubedbcom-singlestore-editor/ui/edit-ui.yaml index 0416323df7..51e87cda73 100644 --- a/charts/kubedbcom-singlestore-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-singlestore-editor/ui/edit-ui.yaml @@ -1,1110 +1,970 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - discriminator: - repoInitialSelectionStatus: - type: string - scheduleBackup: - default: "yes" - type: string +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - computed: initScheduleBackupForEdit - if: showScheduleBackup - label: - text: labels.backup.title - onChange: onScheduleBackupChange + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - text: options.yesOrNo.yes.text - value: "yes" - - text: options.yesOrNo.no.text - value: "no" - schema: - $ref: discriminator#/properties/scheduleBackup - type: radio - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true + options: + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig + elements: + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails + elements: + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType + options: + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + label: Topology + if: + type: function + name: dbTypeEqualsTo|topology + showLabels: false + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute + elements: + # Aggregator section + - type: block-layout + label: Aggregator + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/compute/aggregator/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-aggregator-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|aggregator|min + loader: + name: getMachines|aggregator|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-aggregator-max + watcher: + func: onMachineChange|aggregator + paths: + - temp/properties/allowedMachine-aggregator-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-aggregator-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|aggregator|max + loader: + name: getMachines|aggregator|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-aggregator-min + watcher: + func: onMachineChange|aggregator + paths: + - temp/properties/allowedMachine-aggregator-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|aggregator + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/controlledResources + + # Leaf section + - type: block-layout + label: Leaf + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/compute/leaf/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-leaf-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|leaf|min + loader: + name: getMachines|leaf|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-leaf-max + watcher: + func: onMachineChange|leaf + paths: + - temp/properties/allowedMachine-leaf-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-leaf-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|leaf|max + loader: + name: getMachines|leaf|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-leaf-min + watcher: + func: onMachineChange|leaf + paths: + - temp/properties/allowedMachine-leaf-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|leaf + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/controlledResources + + # combined mode - node only + - type: block-layout + label: Combined + if: + type: function + name: dbTypeEqualsTo|standalone + showLabels: false + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean + # Node section + - type: block-layout + label: Node + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/compute/node/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-node-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|node|min + loader: + name: getMachines|node|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-node-max + watcher: + func: onMachineChange|node + paths: + - temp/properties/allowedMachine-node-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-node-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|node|max + loader: + name: getMachines|node|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-node-min + watcher: + func: onMachineChange|node + paths: + - temp/properties/allowedMachine-node-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|node + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/nodeTopology elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - if: showBackupForm - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.4.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: storage-autoscaler + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - type: block-layout + showLabels: false elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/compute/aggregator/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-aggregator-max: - type: string - allowedMachine-aggregator-min: - type: string + - type: block-layout + showLabels: false elements: - - computed: setAllowedMachine|aggregator|min - disableUnselect: true - fetch: getMachines|aggregator|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|aggregator - schema: - $ref: discriminator#/properties/allowedMachine-aggregator-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|aggregator|max - disableUnselect: true - fetch: getMachines|aggregator|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|aggregator - schema: - $ref: discriminator#/properties/allowedMachine-aggregator-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|aggregator - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator/properties/controlledResources - type: multiselect - if: dbTypeEqualsTo|topology - label: - text: Aggregator - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/aggregator - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/compute/leaf/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-leaf-max: - type: string - allowedMachine-leaf-min: - type: string + # aggregator storage + - type: block-layout + label: Aggregator + if: + type: function + name: dbTypeEqualsTo|topology + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/aggregator/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/scalingRules + loader: setValueFromDbDetails|/resources/kubedbComSinglestore/spec/topology/aggregator/storage/resources/requests/storage + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/aggregator/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/upperBound + + - type: block-layout + showLabels: false elements: - - computed: setAllowedMachine|leaf|min - disableUnselect: true - fetch: getMachines|leaf|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|leaf - schema: - $ref: discriminator#/properties/allowedMachine-leaf-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|leaf|max - disableUnselect: true - fetch: getMachines|leaf|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|leaf - schema: - $ref: discriminator#/properties/allowedMachine-leaf-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|leaf - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf/properties/controlledResources - type: multiselect - if: dbTypeEqualsTo|topology - label: - text: Leaf - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/leaf - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/compute/node/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-node-max: - type: string - allowedMachine-node-min: - type: string + # leaf storage + - type: block-layout + label: Leaf + if: + type: function + name: dbTypeEqualsTo|topology + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/leaf/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/scalingRules + loader: setValueFromDbDetails|/resources/kubedbComSinglestore/spec/topology/leaf/storage/resources/requests/storage + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/leaf/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/upperBound + + - type: block-layout + showLabels: false elements: - - computed: setAllowedMachine|node|min - disableUnselect: true - fetch: getMachines|node|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|node - schema: - $ref: discriminator#/properties/allowedMachine-node-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|node|max - disableUnselect: true - fetch: getMachines|node|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|node - schema: - $ref: discriminator#/properties/allowedMachine-node-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|node - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node/properties/controlledResources - type: multiselect - if: dbTypeEqualsTo|standalone - label: - text: node - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/node - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: SelectNodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.9.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean - elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComSinglestore/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean - elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComSinglestore/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: + # node storage (standalone) + - type: block-layout + label: Node + if: + type: function + name: dbTypeEqualsTo|standalone + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties - type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComSinglestore/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComSinglestore/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/node/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/expansionMode + - type: threshold-input + label: UsageThreshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/usageThreshold + - type: scaling-rules + loader: setValueFromDbDetails|/resources/kubedbComSinglestore/spec/topology/node/storage/resources/requests/storage + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules + - type: input + label: UpperBound + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/node/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound + + - type: block-layout + label: OpsRequest Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - computed: getDbDetails - if: returnFalse - type: input - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/aggregator/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/aggregator/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/aggregator/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator/properties/upperBound - type: input - if: dbTypeEqualsTo|topology - label: - text: Standalone - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/aggregator - show_label: true - type: single-step-form - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/leaf/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/trigger - type: select - - label: - text: Expansion Mode + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComSinglestore/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection + elements: + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/agent + isHorizontal: true options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComSinglestore/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComSinglestore/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/leaf/scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/leaf/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf/properties/upperBound - type: input - if: dbTypeEqualsTo|topology - label: - text: Standalone - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/leaf - show_label: true - type: single-step-form - type: single-step-form - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/node/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/node/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComSinglestoreAutoscaler/spec/storage/node/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound - type: input - if: dbTypeEqualsTo|standalone - label: - text: Standalone - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/storage/properties/node - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSinglestoreAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.10.label -- form: - discriminator: - binding: - default: false - type: boolean + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComSinglestore/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: + type: input + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComSinglestore/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: binding + label: Gateway Binding elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -type: multi-step-form + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-singlestore-editor/ui/functions.js b/charts/kubedbcom-singlestore-editor/ui/functions.js index e979c53f20..69a2f14eb5 100644 --- a/charts/kubedbcom-singlestore-editor/ui/functions.js +++ b/charts/kubedbcom-singlestore-editor/ui/functions.js @@ -1,3279 +1,1515 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + + initRepositoryChoiseForEdit() + + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function initScheduleBackup() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) + + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } -} -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + function onScheduleBackupChange() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + if (scheduleBackup === 'no') { + // delete stashAppscodeComBackupConfiguration + commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') + commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') + // delete annotation from kubedbComSinglestore annotation + deleteKubeDbComSinglestoreDbAnnotation(getValue, model, commit) + } else { + const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // create stashAppscodeComBackupConfiguration and initialize it if not exists - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + const dbName = getValue(model, '/metadata/release/name') - const resources = (resp && resp.data && resp.data.items) || [] + if ( + !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && + !isBluePrint + ) { + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration', + value: stashAppscodeComBackupConfiguration, + }) + commit('wizard/model$update', { + path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', + value: dbName, + force: true, + }) + } + } + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] + function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false } -} -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} + function getBackupConfigsAndAnnotations(getValue, model) { + const stashAppscodeComBackupConfiguration = getValue( + model, + '/resources/stashAppscodeComBackupConfiguration', + ) -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} + const coreKubestashComBackupConfiguration = getValue( + model, + '/resources/coreKubestashComBackupConfiguration', + ) + const kubeStashTarget = coreKubestashComBackupConfiguration?.spec?.target -function isNotShardModeSelected({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComSinglestore/spec') - const hasShardTopology = getValue(model, '/resources/kubedbComSinglestore/spec/shardTopology') - return !hasShardTopology -} + const mongoDB = getValue(model, '/resources/kubedbComSinglestore') + const mongoDbKind = mongoDB?.apiVersion?.split('/')?.at(0) -function isShardModeSelected({ model, getValue, watchDependency, commit }) { - const resp = !isNotShardModeSelected({ model, getValue, watchDependency }) - if (resp) { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_config') - } - return resp -} + let isKubeStash = false + if ( + mongoDB?.kind === kubeStashTarget.kind && + mongoDB?.metadata?.name === kubeStashTarget?.name && + mongoDB?.metadata?.namespace === kubeStashTarget?.namespace && + mongoDbKind === kubeStashTarget?.apiGroup + ) { + isKubeStash = true + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const kubedbComSinglestoreAnnotations = + getValue(model, '/resources/kubedbComSinglestore/metadata/annotations') || {} - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const isBluePrint = Object.keys(kubedbComSinglestoreAnnotations).some( + (k) => + k === 'stash.appscode.com/backup-blueprint' || + k === 'stash.appscode.com/schedule' || + k.startsWith('params.stash.appscode.com/'), + ) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + return { + stashAppscodeComBackupConfiguration, + isBluePrint, + isKubeStash, + } + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + function deleteKubeDbComSinglestoreDbAnnotation(getValue, model, commit) { + const annotations = + getValue(model, '/resources/kubedbComSinglestore/metadata/annotations') || {} + const filteredKeyList = + Object.keys(annotations).filter( + (k) => + k !== 'stash.appscode.com/backup-blueprint' && + k !== 'stash.appscode.com/schedule' && + !k.startsWith('params.stash.appscode.com/'), + ) || [] + const filteredAnnotations = {} + filteredKeyList.forEach((k) => { + filteredAnnotations[k] = annotations[k] + }) + commit('wizard/model$update', { + path: '/resources/kubedbComSinglestore/metadata/annotations', + value: filteredAnnotations, + }) } - return ans -} + // backup form + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false + } -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let namespaceList = [] + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComSinglestore') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + // get values.yaml to populate data when backup-config is being created + try { + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - return ans -} + const resp = await axios.get(url) -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} + } catch (e) { + console.log(e) + } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + // check config with metadata name first + let config = configs?.find( + (item) => + item.metadata?.name === name && + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) -function returnTrue() { - return true -} + // set backup switch here + isBackupOn = !!config -function returnStringYes() { - return 'yes' -} + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset -// ************************* Basic Info ********************************************** -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, - } + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions + } - const resources = (resp && resp.data && resp.data.items) || [] + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + setDiscriminatorValue('isBackupDataLoaded', true) + } - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions - } catch (e) { - console.log(e) - return [] + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') } -} -// ************************* Auth Secret Field ****************************************** -function showAuthPasswordField({ model, getValue, watchDependency }) { - watchDependency('model#/resources') - const modelPathValue = getValue(model, '/resources') - return !!( - modelPathValue && - modelPathValue.secret && - modelPathValue.secret.metadata && - modelPathValue.secret.metadata.name && - !showAuthSecretField({ model, getValue, watchDependency }) - ) -} + function setBackupType() { + return 'BackupConfig' + } -function showAuthSecretField({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComSinglestore/spec') - const modelPathValue = getValue(model, '/resources/kubedbComSinglestore/spec') - return !!(modelPathValue && modelPathValue.authSecret && modelPathValue.authSecret.name) -} + function getTypes() { + const arr = [ + { + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', + }, + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] + + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) + } + return arr + } -function showNewSecretCreateField({ model, getValue, watchDependency, commit }) { - const resp = - !showAuthSecretField({ model, getValue, watchDependency }) && - !showAuthPasswordField({ model, getValue, watchDependency }) - const secret = getValue(model, '/resources/secret_auth') - if (resp && !secret) { + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') commit('wizard/model$update', { - path: '/resources/secret_auth', - value: { - data: { - password: '', - }, - }, + path: '/backupType', + value: type, + force: true, + }) + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), + force: true, + }) + } + commit('wizard/model$delete', '/context') + commit('wizard/model$update', { + path: '/resources/kubedbComSinglestore', + value: objectCopy(dbResource), force: true, }) } - return resp -} -// ********************* Database Mode *********************** -function isNotStandaloneMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Standalone' -} - -function showCommonStorageClassAndSizeField({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(mode) -} -function setDatabaseMode({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/resources/kubedbComSinglestore/spec') + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') - watchDependency('model#/resources/kubedbComSinglestore/spec') - if (modelPathValue.shardTopology) { - return 'Sharded' - } else if (modelPathValue.replicaSet) { - return 'Replicaset' - } else { - return 'Standalone' + return selectedType === type } -} - -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, model, getValue, watchDependency, discriminator }, - mode, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const databaseModeShard = getValue(discriminator, '/activeDatabaseMode') === 'Sharded' - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - storageClassList = resources - const path = - mode === 'shard' - ? '/resources/kubedbComSinglestore/spec/shardTopology/shard/storage/storageClassName' - : '/resources/kubedbComSinglestore/spec/storage/storageClassName' - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ getValue, commit, model, discriminator }) - return resources -} -function setStorageClass({ getValue, commit, model, discriminator }) { - const deletionPolicy = getValue(model, 'resources/kubedbComSinglestore/spec/deletionPolicy') || '' - const suffix = '-retain' - let storageClass = '' + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) + } - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') + if (blueprintSwitch) addLabelAnnotation('annotations') + else deleteLabelAnnotation('annotations') + } - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver + } - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComSinglestore/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + commit('wizard/model$delete', path) } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value + } + + function addLabelAnnotation(type) { + const obj = objectCopy(initialDbMetadata[type]) + + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found + obj['kubedb.com/archiver'] = 'true' } + + commit('wizard/model$update', { + path: `/resources/kubedbComSinglestore/metadata/${type}`, + value: obj, + force: true, + }) } - const mode = getValue(discriminator, '/activeDatabaseMode') + function deleteLabelAnnotation(type) { + const obj = initialDbMetadata[type] + + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] - if (mode === 'Sharded') { commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/shard/storage/storageClassName', - value: storageClass, + path: `/resources/kubedbComSinglestore/metadata/${type}`, + value: obj, force: true, }) + } + + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } + + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, + path: '/context', + value: context, force: true, }) - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/storage') - } else { + if (context === 'Create') { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, + force: true, + }) + } + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) + } + + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) + const list = filteredList?.map((ele) => ele.metadata.name) + return list + } + + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) + commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/storage/storageClassName', - value: storageClass, + path: '/resources/coreKubestashComBackupConfiguration', + value: configDetails, force: true, }) } -} -function updateConfigServerStorageClass({ getValue, model, commit }) { - const storageClass = - getValue( - model, - '/resources/kubedbComSinglestore/spec/shardTopology/shard/storage/storageClassName', - ) || '' - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/configServer/storage/storageClassName', - value: storageClass, - force: true, - }) -} + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' + } + + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' + } + + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName + } -function deleteDatabaseModePath({ discriminator, getValue, commit, model }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - const modelSpec = getValue(model, '/resources/kubedbComSinglestore/spec') - if (mode === 'Sharded') { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/podTemplate') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/configSecret') + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } + + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' + } + + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - commit('wizard/model$delete', '/resources/secret_config') + return repoInitialSelectionStatus + } - if (!modelSpec.shardTopology) { + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology', - value: { - configServer: { - replicas: 3, - storage: { - resources: { - requests: { - storage: '', - }, - }, - }, - }, - mongos: { - replicas: 2, - }, - shard: { - replicas: 3, - shards: 3, - storage: { - resources: { - requests: { - storage: '', - }, - }, - }, - }, + path: modelPath, + value: session, + }) + } + } + + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComSinglestore/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'SinglestoreBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, }, + }, + } + + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComSinglestoreBinding', + value: bindingValues, force: true, }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComSinglestoreBinding') } - } else if (mode === 'Replicaset') { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/shardTopology') + } + + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComSinglestoreBinding') + return isExposeBinding + } + + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } + + /********** Compute Autoscaling ********** */ - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') + let autoscaleType = '' + let dbDetails = {} - if (!modelSpec.replicaSet) { + function isConsole() { + const isKube = isKubedb() + + if (isKube) { + const dbName = storeGet('/route/params/name') || '' commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/replicaSet', - value: { name: '' }, + path: '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', + value: dbName, force: true, }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/replicas', - value: 3, + path: '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/name', + value: modifiedName, force: true, }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace', + value: namespace, + force: true, + }) + } } - } else if (mode === 'Standalone') { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/shardTopology') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/replicaSet') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/replicas') + return !isKube + } - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') + function isKubedb() { + return !!storeGet('/route/params/actions') } -} -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode === value -} + function showOpsRequestOptions() { + if (isKubedb() === true) return true + // watchDependency( + // 'model#/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', + // ) + // watchDependency('discriminator#/autoscalingType') + return ( + !!getValue( + model, + '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', + ) && !!getValue(discriminator, '/autoscalingType') + ) + } -// ************************** TLS ******************************88 + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function setApiGroup() { - return 'cert-manager.io' -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComSinglestore/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComSinglestore/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComSinglestore/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComSinglestore/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') + const resources = (resp && resp.data && resp.data.items) || [] - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - if (!url) return [] + async function getDbs() { + // watchDependency('model#/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace') + const namespace = getValue( + model, + '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace', + ) + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { - const resp = await axios.get(url) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/singlestores`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + return { + text: name, + value: name, + } }) - return resources - } catch (e) { - console.log(e) - return [] } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - return !!(resp && resp.length) -} + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || + getValue(model, '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace') || + '' + const name = + storeGet('/route/params/name') || + getValue( + model, + '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', + ) || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/singlestores/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComSinglestore/spec/clusterAuthMode') - return val || 'x509' -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComSinglestore/spec/sslMode') - return val || 'requireSSL' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/clusterAuthMode') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/sslMode') - } -} - -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit( - 'wizard/model$delete', - '/resources/kubedbComSinglestore/spec/monitor/prometheus/exporter', - ) - } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComSinglestore/spec/init/initialized') - watchDependency('model#/resources/kubedbComSinglestore/spec/init/initialized') - return !!initialized -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComSinglestore/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComSinglestore/spec/init/script') - - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} - -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComSinglestore/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComSinglestore/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue( - model, - '/resources/kubedbComSinglestore/spec/init/script/configMap/name', - ) - const secret = getValue( - model, - '/resources/kubedbComSinglestore/spec/init/script/secret/secretName', - ) - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/init/script/secret') - - if ( - !valueExists(model, getValue, '/resources/kubedbComSinglestore/spec/init/script/configMap') - ) { - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComSinglestore/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} - -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) - } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true - } -} - -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} - -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} - -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) - } -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` - - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} - -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - if (type === 'secrets') data = data.filter((ele) => !!ele.data['RESTIC_PASSWORD']) - data = data.map((ele) => ele.metadata.name) - return data - } - } catch (e) { - console.log(e) - } - return [] -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule backup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - - const coreKubestashComBackupConfiguration = getValue( - model, - '/resources/coreKubestashComBackupConfiguration', - ) - const kubeStashTarget = coreKubestashComBackupConfiguration?.spec?.target - - const mongoDB = getValue(model, '/resources/kubedbComSinglestore') - const mongoDbKind = mongoDB?.apiVersion?.split('/')?.at(0) - - let isKubeStash = false - if ( - mongoDB?.kind === kubeStashTarget.kind && - mongoDB?.metadata?.name === kubeStashTarget?.name && - mongoDB?.metadata?.namespace === kubeStashTarget?.namespace && - mongoDbKind === kubeStashTarget?.apiGroup - ) { - isKubeStash = true - } - - const kubedbComSinglestoreAnnotations = - getValue(model, '/resources/kubedbComSinglestore/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComSinglestoreAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - isKubeStash, - } -} - -function deleteKubeDbComMongDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComSinglestore/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubeDbComMongDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComSinglestore/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComSinglestore annotation - deleteKubeDbComMongDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -async function initBackupData({ storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComSinglestore') - initialDbMetadata = objectCopy(dbResource.metadata) - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - - // set backup switch here - isBackupOn = !!config - - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends - - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` - - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions - } - - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, - } - - setDiscriminatorValue('isBackupDataLoaded', true) -} - -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} - -async function setBackupType() { - return 'BackupConfig' -} - -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - return arr -} - -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), - force: true, - }) - } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore', - value: objectCopy(dbResource), - force: true, - }) -} - -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') - - return selectedType === type -} - -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations - - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} - -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} - -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} - -function onArchiverChange({ getValue, discriminator, commit }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComSinglestore/spec/archiver' - if (archiverSwitch) { - commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, - }) - } else { - commit('wizard/model$delete', path) - } -} - -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) - - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' - } - - commit('wizard/model$update', { - path: `/resources/kubedbComSinglestore/metadata/${type}`, - value: obj, - force: true, - }) -} - -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] - - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] - - commit('wizard/model$update', { - path: `/resources/kubedbComSinglestore/metadata/${type}`, - value: obj, - force: true, - }) -} - -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} - -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, - force: true, - }) - } -} - -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} - -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} - -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} - -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} - -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} - -function getNamespaceArray() { - return namespaceList -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) || [] - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} - -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComSinglestore/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubeDbComMongDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = - getValue(model, '/resources/kubedbComSinglestore/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComSinglestore/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComSinglestore/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComSinglestore/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComSinglestore/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComSinglestore/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretShardConfig = getValue(model, '/resources/secret_shard_config') - if (hasSecretShardConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/shard/configSecret/name', - value: `${dbName}-shard-config`, - force: true, - }) - } - - // to reset shard configSecret name field - const hasSecretConfigServerConfig = getValue(model, '/resources/secret_configserver_config') - if (hasSecretConfigServerConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/configServer/configSecret/name', - value: `${dbName}-configserver-config`, - force: true, - }) - } - - // to reset mongos configSecret name field - const hasSecretMongosConfig = getValue(model, '/resources/secret_mongos_config') - if (hasSecretMongosConfig) { commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/mongos/configSecret/name', - value: `${dbName}-mongos-config`, + path: `/metadata/release/name`, + value: name, force: true, }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComSinglestore/spec/monitor/agent') - if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], + path: `/metadata/release/namespace`, + value: namespace, force: true, }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -/************************************* Database Secret Section ********************************************/ - -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComSinglestore/spec/authSecret') - - return !authSecret -} - -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') - - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} - -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} - -function setAuthSecretPassword({ model, getValue }) { - const encodedPassword = getValue(model, '/resources/secret_auth/data/password') - return encodedPassword ? decodePassword({}, encodedPassword) : '' -} - -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - - if (stringPassword) { commit('wizard/model$update', { - path: '/resources/secret_auth/data/password', - value: encodePassword({}, stringPassword), + path: `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name`, + value: name, force: true, }) commit('wizard/model$update', { - path: '/resources/secret_auth/data/username', - value: encodePassword({}, 'root'), + path: `/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, force: true, }) - } else { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_auth') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] } -} - -//////////////////////////////////////// Service Monitor ////////////////////////////////////////////////////// - -//////////////////// service monitor /////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_config') - } else { - const value = getValue(model, '/resources/secret_config') - if (!value) { + function initMetadata() { + const dbName = + getValue( + model, + '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', + ) || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) commit('wizard/model$update', { - path: '/resources/secret_config', - value: {}, + path: '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/name', + value: modifiedName, force: true, }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function onConfigurationChange({ getValue, commit, discriminator, model }) { - const value = getValue(discriminator, '/configuration') - commit('wizard/model$update', { - path: '/resources/secret_config/stringData/mongod.conf', - value: value, - force: true, - }) - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/configSecret/name', - value: configSecretName, - force: true, - }) -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setSecretConfigNamespace({ getValue, model, watchDependency }) { - watchDependency('model#/metadata/release/namespace') - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -//////////////////// custom config for sharded topology ///////////////// - -function setConfigurationSourceShard({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceShard') - if (src) return src - const value = getValue(model, '/resources/secret_shard_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function setConfigurationSourceConfigServer({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceConfigServer') - if (src) return src - const value = getValue(model, '/resources/secret_configserver_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function setConfigurationSourceMongos({ model, getValue, discriminator }) { - const src = getValue(discriminator, '/configurationSourceMongos') - if (src) return src - const value = getValue(model, '/resources/secret_mongos_config') - return value ? 'create-new-config' : 'use-existing-config' -} - -function isSchemaOf(schema) { - if (schema === 'discriminator#/configurationSourceShard') { - return 'shard' - } else if (schema === 'discriminator#/configurationSourceConfigServer') { - return 'configserver' - } else { - return 'mongos' - } -} - -function disableConfigSourceOption({ - itemCtx, - discriminator, - getValue, - watchDependency, - elementUi, -}) { - watchDependency('discriminator#/configurationSourceShard') - watchDependency('discriminator#/configurationSourceConfigServer') - watchDependency('discriminator#/configurationSourceMongos') - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - if ( - itemCtx.value !== 'use-existing-config' && - itemCtx.value !== 'create-new-config' && - (configSrcShard === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcConfigServer === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret` || - configSrcMongos === `same-as-${isSchemaOf(elementUi.schema.$ref)}-config-secret`) - ) { - return true - } - if ( - itemCtx.value === 'same-as-shard-config-secret' && - configSrcShard !== 'use-existing-config' && - configSrcShard !== 'create-new-config' - ) { - return true - } - if ( - itemCtx.value === 'same-as-configserver-config-secret' && - configSrcConfigServer !== 'use-existing-config' && - configSrcConfigServer !== 'create-new-config' - ) { - return true - } - if ( - itemCtx.value === 'same-as-mongos-config-secret' && - configSrcMongos !== 'use-existing-config' && - configSrcMongos !== 'create-new-config' - ) { - return true - } - return false -} -function onConfigurationSourceMongosChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceMongos') - const configSecretName = `${getValue(model, '/metadata/release/name')}-mongos-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_mongos_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_mongos_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_mongos_config', - value: {}, - force: true, - }) - } - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/mongos/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'mongos', - configurationSource, - '/configurationMongos', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'shard', 'mongos') - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'mongos') + // delete the other type object from model + if (type === 'compute') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/storage', + ) + if (type === 'storage') + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute', + ) } -} -function onConfigurationSourceShardChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceShard') - const configSecretName = `${getValue(model, '/metadata/release/name')}-shard-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_shard_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', + function onNamespaceChange({ model, getValue, commit }) { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace', ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_shard_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_shard_config', - value: {}, - force: true, - }) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', + ) } - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/shard/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'shard', - configurationSource, - '/configurationShard', - ) - } else if (configurationSource === 'same-as-configserver-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'configserver', 'shard') - } else if (configurationSource === 'same-as-mongos-config-secret') { - transferConfigSecret({ commit, model, getValue }, 'mongos', 'shard') } -} - -function onConfigurationSourceConfigServerChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSourceConfigServer') - const configSecretName = `${getValue(model, '/metadata/release/name')}-configserver-config` - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_configserver_config') - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'create-new-config') { - const value = getValue(model, '/resources/secret_configserver_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_configserver_config', - value: {}, - force: true, + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name }) + return mappedList + } catch (e) { + console.log(e) } - commit('wizard/model$update', { - path: '/resources/kubedbComSinglestore/spec/shardTopology/configServer/configSecret/name', - value: configSecretName, - force: true, - }) - onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - 'configserver', - configurationSource, - '/configurationConfigServer', - ) - } else if (configurationSource === 'same-as-shard-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceShard') - transferConfigSecret( - { commit, model, getValue }, - 'shard', - 'configserver', - configurationSourceReference, - ) - } else if (configurationSource === 'same-as-mongos-config-secret') { - const configurationSourceReference = getValue(discriminator, '/configurationSourceMongos') - transferConfigSecret( - { commit, model, getValue }, - 'mongos', - 'configserver', - configurationSourceReference, - ) + return [] } -} -function transferConfigSecret({ commit, model, getValue }, src, des) { - const isShardedMode = getValue(model, '/resources/kubedbComSinglestore/spec/shardTopology') - if (isShardedMode) { - commit('wizard/model$update', { - path: `/resources/kubedbComSinglestore/spec/shardTopology/${ - des === 'configserver' ? 'configServer' : des - }/configSecret/name`, - value: getValue( + function isNodeTopologySelected() { + // watchDependency( + // 'model#/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute/nodeTopology/name', + // ) + const nodeTopologyName = + getValue( model, - `/resources/kubedbComSinglestore/spec/shardTopology/${ - src === 'configserver' ? 'configServer' : src - }/configSecret/name`, - ), - force: true, - }) - - commit('wizard/model$delete', `/resources/secret_${des}_config`) + '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute/nodeTopology/name', + ) || '' + return !!nodeTopologyName.length } -} -function onConfigSecretModelChange( - { commit, model, getValue, discriminator }, - configType, - configSrc, - discriminatorPath, -) { - if (configSrc === 'create-new-config') { - const value = getValue(discriminator, discriminatorPath) + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute/${type}/controlledResources` commit('wizard/model$update', { - path: `/resources/secret_${configType}_config/stringData/mongod.conf`, - value: value, + path: path, + value: list, force: true, - }) - } - const configSrcShard = getValue(discriminator, '/configurationSourceShard') - const configSrcConfigServer = getValue(discriminator, '/configurationSourceConfigServer') - const configSrcMongos = getValue(discriminator, '/configurationSourceMongos') - - if (configSrcShard === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'shard') - } - if (configSrcConfigServer === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'configserver') - } - if (configSrcMongos === `same-as-${configType}-config-secret`) { - transferConfigSecret({ commit, model, getValue }, configType, 'mongos') - } -} - -function setConfiguration({ model, getValue }) { - return getValue(model, '/resources/secret_config/stringData/mongod.conf') -} - -function setConfigurationShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/stringData/mongod.conf') - return value -} - -function setConfigurationConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/stringData/mongod.conf') - return value -} - -function setConfigurationMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/stringData/mongod.conf') - return value -} - -function setConfigurationFiles({ model, getValue }) { - const value = getValue(model, '/resources/secret_config/data/mongod.conf') - return atob(value) -} - -function setConfigurationFilesShard({ model, getValue }) { - const value = getValue(model, '/resources/secret_shard_config/data/mongod.conf') - return atob(value) -} - -function setConfigurationFilesConfigServer({ model, getValue }) { - const value = getValue(model, '/resources/secret_configserver_config/data/mongod.conf') - return atob(value) -} - -function setConfigurationFilesMongos({ model, getValue }) { - const value = getValue(model, '/resources/secret_mongos_config/data/mongod.conf') - return atob(value) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/configSecret') - commit( - 'wizard/model$delete', - '/resources/kubedbComSinglestore/spec/shardTopology/shard/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComSinglestore/spec/shardTopology/configServer/configSecret', - ) - commit( - 'wizard/model$delete', - '/resources/kubedbComSinglestore/spec/shardTopology/mongos/configSecret', - ) - commit('wizard/model$delete', '/resources/secret_config') - commit('wizard/model$delete', '/resources/secret_shard_config') - commit('wizard/model$delete', '/resources/secret_configserver_config') - commit('wizard/model$delete', '/resources/secret_mongos_config') + }) + return list } -} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value + } -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + function setApplyToIfReady() { + return 'IfReady' + } - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/name', - value: modifiedName, - force: true, - }) + function setMetadata() { + const dbname = storeGet('/route/params/name') || '' const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { + if (mode === 'standalone-step') { + commit('wizard/model$update', { + path: '/metadata/release/name', + value: dbname, + force: true, + }) commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace', + path: '/metadata/release/namespace', value: namespace, force: true, }) } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency( - 'model#/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', - ) - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue( + function hasAnnotations() { + const annotations = getValue( model, - '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', - ) && !!getValue(discriminator, '/autoscalingType') - ) -} + '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + return !!instance + } - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + function hasNoAnnotations() { + return !hasAnnotations() + } - const resources = (resp && resp.data && resp.data.items) || [] + function dbTypeEqualsTo(type) { + // watchDependency('discriminator#/dbDetails') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + const { spec } = dbDetails || {} + const { topology } = spec || {} + let verd = '' + if (topology) verd = 'topology' + else { + verd = 'standalone' } - }) -} + clearSpecModel(verd) + return type === verd && spec + } -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function clearSpecModel(dbtype) { + if (dbtype === 'standalone') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/cluster`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/sentinel`, + ) + } else if (dbtype === 'cluster') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/standalone`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/sentinel`, + ) + } else if (dbtype === 'sentinel') { + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/standalone`, + ) + commit( + 'wizard/model$delete', + `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/cluster`, + ) + } + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/singlestores`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } - const resources = (resp && resp.data && resp.data.items) || [] + const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) + const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) + const minMaxMachine = `${minMachine},${maxMachine}` - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + parsedInstance[type] = minMaxMachine + const instanceString = JSON.stringify(parsedInstance) + annotations['kubernetes.io/instance-type'] = instanceString + + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute/${type}` + + if (minMachine && maxMachine && instance !== instanceString) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: annotations, + force: true, + }) } - }) -} + } + + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } + } + } + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } + + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/singlestores/${name}`, + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) + + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) + return [] } } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) -async function dbTypeEqualsTo({ axios, storeGet, watchDependency, model, getValue, commit }, type) { - watchDependency('discriminator#/dbDetails') + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else { - verd = 'standalone' + return ans } - clearSpecModel({ commit }, verd) - return type === verd && spec -} -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'standalone') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/cluster`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'cluster') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/sentinel`, - ) - } else if (dbtype === 'sentinel') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/standalone`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/${autoscaleType}/cluster`, - ) + /****** Monitoring *********/ + + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus } -} -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name') || - '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComSinglestore/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComSinglestore/spec/monitor') + } + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/name', - value: modifiedName, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) - - // delete the other type object from model - if (type === 'compute') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/storage', - ) - if (type === 'storage') - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute', - ) -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', - ) } -} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency( - 'model#/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', - ) - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComSinglestore/spec/monitor/prometheus/exporter', + value: {}, + force: true, + }) + } else { + commit( + 'wizard/model$delete', + '/resources/kubedbComSinglestore/spec/monitor/prometheus/exporter', + ) + } } - return [] -} -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( - model, - '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} + function isValueExistInModel(path) { + const modelValue = getValue(model, path) || null + return !!modelValue + } -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + // function onNamespaceChange({ commit, model, getValue }) { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComSinglestore/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComSinglestore/spec/metadata/labels') -function setApplyToIfReady() { - return 'IfReady' -} + const agent = getValue(model, '/resources/kubedbComSinglestore/spec/monitor/agent') -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, force: true, }) } - } else { - if (!isNaN(value)) { - value += 'Gi' + } + + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComSinglestore/spec/monitor/agent') + if (agent === 'prometheus.io') { commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], force: true, }) + + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') } } -} -function objectCopy(obj) { - const temp = JSON.stringify(obj) - return JSON.parse(temp) -} + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/databaseRef/name', + ) + } + } -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComSinglestoreBinding') - return isExposeBinding -} + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` + + const isKube = !!storeGet('/route/params/actions') + + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/singlestoreopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` + } + + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' + } + } -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 labels = getValue(model, '/resources/kubedbComSinglestore/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'SinglestoreBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { - name: dbName, - namespace: dbNamespace, - }, - }, + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } } - if (value) { - await commit('wizard/model$update', { - path: '/resources/catalogAppscodeComSinglestoreBinding', - value: bindingValues, - force: true, - }) - } else { - await commit('wizard/model$delete', '/resources/catalogAppscodeComSinglestoreBinding') + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } -} -function setMetadata({ storeGet, mode, commit }) { - const dbname = storeGet('/route/params/name') || '' - const namespace = storeGet('/route/query/namespace') || '' - if (mode === 'standalone-step') { - commit('wizard/model$update', { - path: '/metadata/release/name', - value: dbname, - force: true, + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, - force: true, + + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } -} -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/singlestoreopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=VerticalScaling` -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComSinglestore/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') + + if (!configMapName) return [] - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + const configMaps = (resp && resp.data && resp.data.data) || {} + + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) + + return configMapKeys } catch (e) { console.log(e) return [] } } -} -function setAllowedMachine({ model, getValue }, type, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const machine = parsedInstance[type] || '' - const mx = machine?.includes(',') ? machine.split(',')[1] : '' - const mn = machine?.includes(',') ? machine.split(',')[0] : '' + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - if (minmax === 'min') return mn - else return mx -} + const secrets = (resp && resp.data && resp.data.items) || [] -async function getMachines({ getValue, watchDependency, discriminator }, type, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${type}-${depends}` + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } + } - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComSinglestore/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) + if (!secretName) return [] - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) - return dependantIndex === -1 ? machines : filteredMachine -} + const secret = (resp && resp.data && resp.data.data) || {} -function hasAnnotations({ model, getValue }, type) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) - return !!instance -} + return secretKeys + } catch (e) { + console.log(e) + return [] + } + } -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} + function returnFalse() { + return false + } -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComSinglestoreAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - - const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) - const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) - const minMaxMachine = `${minMachine},${maxMachine}` - - parsedInstance[type] = minMaxMachine - const instanceString = JSON.stringify(parsedInstance) - annotations['kubernetes.io/instance-type'] = instanceString - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComSinglestoreAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== instanceString) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComSinglestoreBinding') + return isExposeBinding + } + + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComSinglestore/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'SinglestoreBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } + + if (value) { + commit('wizard/model$update', { + path: '/resources/catalogAppscodeComSinglestoreBinding', + value: bindingValues, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComSinglestoreBinding') + } } -} -return { - getOpsRequestUrl, - setMetadata, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - isBlueprintOption, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - isVariantAvailable, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - isNotShardModeSelected, - isShardModeSelected, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - getMongoDbVersions, - showAuthPasswordField, - showAuthSecretField, - showNewSecretCreateField, - isNotStandaloneMode, - showCommonStorageClassAndSizeField, - setDatabaseMode, - getStorageClassNames, - setStorageClass, - deleteDatabaseModePath, - isEqualToDatabaseMode, - setApiGroup, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubeDbComMongDbAnnotation, - addKubeDbComMongDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - setAuthSecretPassword, - onAuthSecretPasswordChange, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - onConfigurationChange, - setConfigurationSource, - setSecretConfigNamespace, - setConfigurationSourceShard, - setConfigurationSourceConfigServer, - setConfigurationSourceMongos, - isSchemaOf, - disableConfigSourceOption, - onConfigurationSourceMongosChange, - onConfigurationSourceShardChange, - onConfigurationSourceConfigServerChange, - transferConfigSecret, - onConfigSecretModelChange, - setConfiguration, - setConfigurationShard, - setConfigurationConfigServer, - setConfigurationMongos, - setConfigurationFiles, - setConfigurationFilesShard, - setConfigurationFilesConfigServer, - setConfigurationFilesMongos, - onSetCustomConfigChange, - getCreateNameSpaceUrl, - updateConfigServerStorageClass, - - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - getNamespaceArray, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value + } + + return { + initScheduleBackup, + initScheduleBackupForEdit, + onScheduleBackupChange, + showBackupForm, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + onBackupTypeChange, + isBackupType, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showConfigList, + showSchedule, + showScheduleBackup, + getDefaultSchedule, + onInputChangeSchedule, + + isConsole, + isKubedb, + showOpsRequestOptions, + getNamespaces, + getDbs, + getDbDetails, + initMetadata, + onNamespaceChange, + fetchNodeTopology, + isNodeTopologySelected, + setControlledResources, + setTrigger, + setApplyToIfReady, + setMetadata, + isRancherManaged, + dbTypeEqualsTo, + onMachineChange, + handleUnit, + setValueFromDbDetails, + + getOpsRequestUrl, + isValueExistInModel, + onEnableMonitoringChange, + showMonitoringSection, + onAgentChange, + getResources, + isEqualToModelPathValue, + onCustomizeExporterChange, + showCustomizeExporterSection, + onLabelChange, + setValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + getNamespacedResourceList, + returnFalse, + + isBindingAlreadyOn, + addOrRemoveBinding, + setValueFromDbDetails, + hasAnnotations, + hasNoAnnotations, + } } diff --git a/charts/kubedbcom-solr-editor-options/ui/create-ui.yaml b/charts/kubedbcom-solr-editor-options/ui/create-ui.yaml index dfdbf7a545..9fa1a7c938 100644 --- a/charts/kubedbcom-solr-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-solr-editor-options/ui/create-ui.yaml @@ -1,434 +1,440 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/Solr/versions - if: isToggleOn|databases/Solr/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/Solr/properties/versions/properties/default - type: select - - computed: getDefault|databases/Solr/mode - fetch: getAdminOptions|databases/Solr/mode - hasDescription: true - if: isToggleOn|databases/Solr/mode - label: - text: labels.database.mode - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/replicas - type: input - if: isEqualToModelPathValue|[Replicaset]|/spec/mode - type: single-step-form - - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/overseer/properties/replicas - type: input - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/overseer/properties/persistence/properties/size - type: input - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/overseer/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/overseer - disabled: isMachineNotCustom|topology/overseer - if: isMachineCustom|topology/overseer - label: - text: labels.cpu - onChange: setRequests|cpu|topology/overseer - schema: - $ref: schema#/properties/spec/properties/topology/properties/overseer/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/overseer - disabled: isMachineNotCustom|topology/overseer - if: isMachineCustom|topology/overseer - label: - text: labels.memory - onChange: setRequests|memory|topology/overseer - schema: - $ref: schema#/properties/spec/properties/topology/properties/overseer/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - type: single-step-form - if: isEqualToModelPathValue|[Topology]|/spec/mode - label: - text: Overseer - show_label: true - type: single-step-form +step: +- type: single-step-form + loader: initBundle + elements: + - if: + type: function + name: returnFalse + init: + type: func + value: initBundle + label: '' + type: label-element + - disableUnselect: true + loader: getAdminOptions|databases/Solr/versions + if: + type: function + name: isToggleOn|databases/Solr/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/Solr/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/Solr/mode + loader: getAdminOptions|databases/Solr/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/Solr/mode + label: Database Mode + schema: schema/properties/spec/properties/mode + type: radio + - elements: + - label: Replica number + schema: schema/properties/spec/properties/replicas + type: input + if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + type: block-layout + - elements: + - label: Replica number + schema: schema/properties/spec/properties/topology/properties/overseer/properties/replicas + type: input + - label: Storage Size + schema: schema/properties/spec/properties/topology/properties/overseer/properties/persistence/properties/size + type: input - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/replicas + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/overseer/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/overseer + disable: isMachineNotCustom|topology/overseer + if: + type: function + name: isMachineCustom|topology/overseer + label: CPU + watcher: + func: setRequests|cpu|topology/overseer + paths: + - schema/properties/spec/properties/topology/properties/overseer/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/overseer/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/persistence/properties/size + - init: + type: func + value: setLimits|memory|topology/overseer + disable: isMachineNotCustom|topology/overseer + if: + type: function + name: isMachineCustom|topology/overseer + label: Memory + watcher: + func: setRequests|memory|topology/overseer + paths: + - schema/properties/spec/properties/topology/properties/overseer/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/overseer/properties/podResources/properties/resources/properties/requests/properties/memory type: input - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/data - disabled: isMachineNotCustom|topology/data - if: isMachineCustom|topology/data - label: - text: labels.cpu - onChange: setRequests|cpu|topology/data - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/data - disabled: isMachineNotCustom|topology/data - if: isMachineCustom|topology/data - label: - text: labels.memory - onChange: setRequests|memory|topology/data - schema: - $ref: schema#/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - type: single-step-form - if: isEqualToModelPathValue|[Topology]|/spec/mode - label: - text: Data - show_label: true - type: single-step-form + type: block-layout + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Overseer + showLabels: true + type: block-layout + - elements: + - label: Replica number + schema: schema/properties/spec/properties/topology/properties/data/properties/replicas + type: input + - label: Storage Size + schema: schema/properties/spec/properties/topology/properties/data/properties/persistence/properties/size + type: input - elements: - - label: - text: labels.replicaset.number - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinator/properties/replicas + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/machine + type: select + - init: + type: func + value: setLimits|cpu|topology/data + disable: isMachineNotCustom|topology/data + if: + type: function + name: isMachineCustom|topology/data + label: CPU + watcher: + func: setRequests|cpu|topology/data + paths: + - schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinator/properties/persistence/properties/size + - init: + type: func + value: setLimits|memory|topology/data + disable: isMachineNotCustom|topology/data + if: + type: function + name: isMachineCustom|topology/data + label: Memory + watcher: + func: setRequests|memory|topology/data + paths: + - schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/data/properties/podResources/properties/resources/properties/requests/properties/memory type: input - - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinator/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu|topology/coordinator - disabled: isMachineNotCustom|topology/coordinator - if: isMachineCustom|topology/coordinator - label: - text: labels.cpu - onChange: setRequests|cpu|topology/coordinator - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinator/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory|topology/coordinator - disabled: isMachineNotCustom|topology/coordinator - if: isMachineCustom|topology/coordinator - label: - text: labels.memory - onChange: setRequests|memory|topology/coordinator - schema: - $ref: schema#/properties/spec/properties/topology/properties/coordinator/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - type: single-step-form - if: isEqualToModelPathValue|[Topology]|/spec/mode - label: - text: Coordinator - show_label: true - type: single-step-form + type: block-layout + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Data + showLabels: true + type: block-layout + - elements: + - label: Replica number + schema: schema/properties/spec/properties/topology/properties/coordinator/properties/replicas + type: input + - label: Storage Size + schema: schema/properties/spec/properties/topology/properties/coordinator/properties/persistence/properties/size + type: input - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/topology/properties/coordinator/properties/podResources/properties/machine type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + - init: + type: func + value: setLimits|cpu|topology/coordinator + disable: isMachineNotCustom|topology/coordinator + if: + type: function + name: isMachineCustom|topology/coordinator + label: CPU + watcher: + func: setRequests|cpu|topology/coordinator + paths: + - schema/properties/spec/properties/topology/properties/coordinator/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/topology/properties/coordinator/properties/podResources/properties/resources/properties/requests/properties/cpu type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + - init: + type: func + value: setLimits|memory|topology/coordinator + disable: isMachineNotCustom|topology/coordinator + if: + type: function + name: isMachineCustom|topology/coordinator + label: Memory + watcher: + func: setRequests|memory|topology/coordinator + paths: + - schema/properties/spec/properties/topology/properties/coordinator/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/topology/properties/coordinator/properties/podResources/properties/resources/properties/requests/properties/memory type: input - if: isEqualToModelPathValue|[Replicaset, Standalone]|/spec/mode - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + type: block-layout + if: + type: function + name: isEqualToModelPathValue|Topology|/spec/mode + label: Coordinator + showLabels: true + type: block-layout + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - if: showStorageSizeField - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory type: input + if: + type: function + name: isEqualToModelPathValue|Replicaset,Standalone|/spec/mode + label: Machine Profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + if: + type: function + name: isToggleOn|storageClasses + label: Storage Class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: showStorageSizeField + label: Storage Size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - elements: + - loader: getAppBindings + label: Name + schema: schema/properties/spec/properties/zookeeperRef/properties/name + type: select + label: ZookeeperRef + showLabels: true + type: block-layout + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - fetch: getAppBindings - label: - text: labels.zookeeperRef.name - schema: - $ref: schema#/properties/spec/properties/zookeeperRef/properties/name - type: select - label: - text: labels.zookeeperRef.label - schema: - $ref: schema#/properties/spec/properties/zookeeperRef - show_label: true - type: single-step-form - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + hideBlock: true + label: Labels & Annotations + showLabels: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy + type: select + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password + schema: schema/properties/spec/properties/authSecret/properties/password + type: input + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + options: + - description: For exploring databases when high-performance is not required. + text: Shared + value: Shared + - description: For production applications with sophisticated workload + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + hideBlock: true + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default - type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - elements: - - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - if: isToggleOn|expose - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - elements: + - label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default + type: switch + if: + type: function + name: isToggleOn|expose + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-solr-editor-options/ui/functions.js b/charts/kubedbcom-solr-editor-options/ui/functions.js index 88c295f076..2649019b08 100644 --- a/charts/kubedbcom-solr-editor-options/ui/functions.js +++ b/charts/kubedbcom-solr-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -319,1033 +321,839 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return value.includes(modelPathValue) -} - -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} - -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(modelPathValue) -} - -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, ) - const resources = (resp && resp.data && resp.data.items) || [] + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('monitoring', false) - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} - -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + async function fetchJsons() { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions -} + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - const secrets = (resp && resp.data && resp.data.items) || [] + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} - -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } - }) - } else { - array = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) }) - .filter((val) => !!val) + } else return filteredlist } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory - } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` } } - if (resource === 'memory') { - commit('wizard/model$update', { - path: reqCommitPath, - value: memory, - force: true, - }) - commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, - force: true, - }) - commit('wizard/model$update', { - path: comparePath, - value: cpu, - force: true, - }) - return cpu + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val } -} -function setRequests({ getValue, model, commit }, resource, type) { - const modelPath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} - -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + if (available.length) { + array = available.map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } + }) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } -} - -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} - -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + const resources = (resp && resp.data && resp.data.items) || [] -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + if (owner && cluster && namespace) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { + items: { + data: { username: null, password: null }, + metadata: { name: null }, + type: null, + }, + }, + }, + }, + ) -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const secrets = (resp && resp.data && resp.data.items) || [] -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } - }) - return val - } catch (e) { - console.log(e) - return [] + const filteredSecrets = secrets.filter((item) => { + const validType = [ + 'kubernetes.io/service-account-token', + 'Opaque', + 'kubernetes.io/basic-auth', + ] + return validType.includes(item.type) + }) + + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + } } + return [] } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { + let placement = [] + let versions = [] + let storageClass = [] + let clusterIssuers = [] + let nodetopologiesShared = [] + let nodetopologiesDedicated = [] + let features = [] + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` - } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, }) - url = url.slice(0, -1) } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val } catch (e) { console.log(e) - return [] } - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, watchDependency, discriminator }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] - } - const isChangeable = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'storageClasses', - ) - if (isChangeable && storageClass) { commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + if (!getValue(model, `/spec/admin/databases/Solr/mode/toggle`)) { + let defMode = getDefault('databases/Solr/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/Solr/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) } - } catch (e) { - console.log(e) - } - return [] -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!features.includes('tls')) { + commit('wizard/model$update', { + path: '/spec/admin/tls/default', + value: false, + force: true, + }) + } + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/form/alert/enabled', + value: 'none', force: true, }) } - } catch (e) { - console.log(e) + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) + } + + setDiscriminatorValue('/bundleApiLoaded', true) } - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/Solr/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/Solr/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/Solr/mode/available') || [] - if (arr.length) defMode = arr[0] - } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return value.split(',').includes(modelPathValue) } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) + + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } + + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } + + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - if (!features.includes('backup')) { + + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } + + function onAuthChange() { commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, + path: '/spec/authSecret/name', + value: '', force: true, }) commit('wizard/model$update', { - path: '/spec/backup/tool', + path: '/spec/authSecret/password', value: '', force: true, }) } - setDiscriminatorValue('/bundleApiLoaded', true) -} - -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } - - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` + function onReferSecretChange() { commit('wizard/model$update', { - path: path, - value: returnArray[0], + path: '/spec/authSecret/name', + value: '', force: true, }) } - return returnArray -} - -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') - - const options = getValue(model, `/spec/admin/${type}/available`) || [] - - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + function returnFalse() { + return false } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } -} + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } + } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory + } else { + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', + path: comparePath, + value: cpu, force: true, }) + return cpu } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} - -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + } - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + function setRequests(resource, type) { + const modelPath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + const commitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + commit('wizard/model$update', { + path: commitPath, + value: val, + force: true, + }) + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - ) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) }) - } else return filteredlist -} - -function returnFalse() { - return false -} - -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} - -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} - -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { + commit('wizard/model$update', { + path: '/spec/admin/storageClasses/default', + value: storageClass, + force: true, + }) + } + } - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length } -} -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, watchDependency, discriminator }, 'alert') - ) -} + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Standalone', 'Replicaset'] + return validType.includes(modelPathValue) + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -async function getAppBindings({ commit, axios, storeGet, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { type: null }, - }, - }, + return returnArray } - setNamespace({ commit, model, getValue }) - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, - { - params: queryParams, - }, - ) - const resources = (resp && resp.data && resp.data.items) || [] + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - const fileredResources = resources - .filter((item) => item.spec?.type === 'kubedb.com/zookeeper') - .map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: `${namespace}/${name}`, - value: name, - } - }) - return fileredResources - } catch (e) { - console.log(e) - return [] - } -} + const options = getValue(model, `/spec/admin/${type}/available`) || [] -function setNamespace({ commit, model, getValue }) { - let modelPathValue = getValue(model, '/metadata/release/namespace') - if (modelPathValue) { - commit('wizard/model$update', { - path: '/spec/zookeeperRef/namespace', - value: modelPathValue, - force: true, - }) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } -} -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && val + } } - return options -} - -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + async function getAppBindings() { + const namespace = getValue(model, '/metadata/release/namespace') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} - -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { type: null }, + }, + }, + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/appcatalog.appscode.com/v1alpha1/appbindings`, + { + params: queryParams, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + const filteredResources = resources + .filter((item) => item.spec?.type === 'kubedb.com/zookeeper') + .map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: `${namespace}/${name}`, + value: name, + } + }) + return filteredResources + } catch (e) { + console.log(e) + return [] + } + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - setLimits, - setRequests, - setNamespace, - getAppBindings, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - showStorageSizeField, - getResources, - getMongoDbVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - getNamespaces, - isToggleOn, - getAdminOptions, - getNodeTopology, - filterNodeTopology, - isMachineNotCustom, - isMachineCustom, - onAuthChange, - clearConfiguration, - isConfigDatabaseOn, - showIssuer, - setMonitoring, - updateAlertValue, - showAlerts, - onBackupSwitch, - setBackup, - getDefault, - showAdditionalSettings, + return { + clearConfiguration, + fetchJsons, + filterNodeTopology, + getCreateNameSpaceUrl, + getDefault, + getDefaultValue, + getMachineListForOptions, + getNamespaces, + getReferSecrets, + getResources, + getSecrets, + initBundle, + isConfigAvailable, + isConfigDatabaseOn, + isEqualToModelPathValue, + isMachineCustom, + isMachineNotCustom, + isRancherManaged, + isVariantAvailable, + onAuthChange, + onReferSecretChange, + returnFalse, + setLimits, + setMachineToCustom, + setMonitoring, + setRequests, + setStorageClass, + showAdditionalSettings, + showAlerts, + showReferSecret, + showReferSecretSwitch, + showSecretDropdown, + showStorageSizeField, + updateAlertValue, + fetchOptions, + getAdminOptions, + getNodeTopology, + checkIfFeatureOn, + isToggleOn, + getAppBindings, + } } diff --git a/charts/kubedbcom-solr-editor/ui/edit-ui.yaml b/charts/kubedbcom-solr-editor/ui/edit-ui.yaml index c9c8c9a55f..6c47bc5497 100644 --- a/charts/kubedbcom-solr-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-solr-editor/ui/edit-ui.yaml @@ -1,1160 +1,1062 @@ -steps: -- form: - discriminator: - dbDetails: - default: false - type: boolean +type: multi-step-form +step: + - type: single-step-form + id: storage-autoscaler + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: SelectDb - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: SelectType - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - discriminator: - topologyMachines: - default: [] - type: array + - type: block-layout + if: + type: function + name: isConsole elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/compute/coordinator/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-coordinator-max: - type: string - allowedMachine-coordinator-min: - type: string + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType + options: + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + elements: + # Storage sections for different node types + - type: block-layout + showLabels: false elements: - - computed: setAllowedMachine|coordinator|min - disableUnselect: true - fetch: getMachines|coordinator|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|coordinator - schema: - $ref: discriminator#/properties/allowedMachine-coordinator-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|coordinator|max - disableUnselect: true - fetch: getMachines|coordinator|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|coordinator - schema: - $ref: discriminator#/properties/allowedMachine-coordinator-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|coordinator - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/controlledResources - type: multiselect - if: isTopology - label: - text: Coordinator - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/compute/data/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-data-max: - type: string - allowedMachine-data-min: - type: string + # Coordinator + - type: block-layout + label: Coordinator + showLabels: true + if: + type: function + name: isTopology + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/storage/coordinator/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/expansionMode + - type: threshold-input + label: Usage Threshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComSolr/spec/topology/coordinator/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/coordinator/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/scalingRules + - type: input + label: Upper Bound + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/coordinator/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/upperBound + + # Data + - type: block-layout + label: Data + showLabels: true + if: + type: function + name: isTopology + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/storage/data/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/expansionMode + - type: threshold-input + label: Usage Threshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComSolr/spec/topology/data/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/data/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/scalingRules + - type: input + label: Upper Bound + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/data/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/upperBound + + # Node + - type: block-layout + label: Node + showLabels: true + if: + type: function + name: isNotTopology + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/storage/node/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/expansionMode + - type: threshold-input + label: Usage Threshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComSolr/spec/topology/node/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/node/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules + - type: threshold-input + label: Upper Bound + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/node/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound + + # Overseer + - type: block-layout + label: Overseer + showLabels: true + if: + type: function + name: isTopology + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/storage/overseer/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/trigger + - type: select + label: Expansion Mode + options: + - text: Online + value: Online + - text: Offline + value: Offline + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/expansionMode + - type: threshold-input + label: Usage Threshold (%) + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/usageThreshold + - type: scaling-rules + label: Scaling Rules + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/scalingRules + loader: setValueFromDbDetails|resources/kubedbComSolr/spec/topology/overseer/storage/resources/requests/storage + watcher: + func: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/overseer/scalingRules|scalingRules + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/scalingRules + - type: input + label: Upper Bound + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/upperBound + watcher: + func: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/overseer/upperBound + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/upperBound + + # Node Topology + - type: block-layout + label: Node Topology + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/nodeTopology elements: - - computed: setAllowedMachine|data|min - disableUnselect: true - fetch: getMachines|data|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|data - schema: - $ref: discriminator#/properties/allowedMachine-data-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|data|max - disableUnselect: true - fetch: getMachines|data|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|data - schema: - $ref: discriminator#/properties/allowedMachine-data-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|data - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/controlledResources - type: multiselect - if: isTopology - label: - text: Data - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/compute/node/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-node-max: - type: string - allowedMachine-node-min: - type: string + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected|storage + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected|storage + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/nodeTopology/properties/scaleDownDiffPercentage + + # Ops Request Options + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions elements: - - computed: setAllowedMachine|node|min - disableUnselect: true - fetch: getMachines|node|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|node - schema: - $ref: discriminator#/properties/allowedMachine-node-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|node|max - disableUnselect: true - fetch: getMachines|node|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|node - schema: - $ref: discriminator#/properties/allowedMachine-node-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|node - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/controlledResources - type: multiselect - if: isNotTopology - label: - text: Node - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/compute/overseer/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/trigger - type: select - - label: - text: PodLifeTimeThreshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-overseer-max: - type: string - allowedMachine-overseer-min: - type: string - elements: - - computed: setAllowedMachine|overseer|min - disableUnselect: true - fetch: getMachines|overseer|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|overseer - schema: - $ref: discriminator#/properties/allowedMachine-overseer-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|overseer|max - disableUnselect: true - fetch: getMachines|overseer|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|overseer - schema: - $ref: discriminator#/properties/allowedMachine-overseer-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|overseer - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/controlledResources - type: multiselect - if: isTopology - label: - text: Overseer - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer - show_label: true - type: single-step-form - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected|compute - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected|compute - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.0.label -- form: - discriminator: - dbDetails: - default: false - type: boolean + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: SelectDb - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: SelectType - onChange: initMetadata - options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - elements: - - elements: - - elements: - - computed: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/storage/coordinator/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/coordinator/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/coordinator/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator/properties/upperBound - type: input - label: - text: Coordinator - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/coordinator - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/storage/data/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/data/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/data/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data/properties/upperBound - type: input - label: - text: Data - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/data - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/storage/node/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/node/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/node/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node/properties/upperBound - type: input - label: - text: Node - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/node - show_label: true - type: single-step-form - - elements: - - computed: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/storage/overseer/trigger - label: - text: Trigger - options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/trigger - type: select - - label: - text: Expansion Mode - options: - - Online - - Offline - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/expansionMode - type: select - - label: - text: UsageThreshold (%) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/usageThreshold - type: input - - addFormLabel: ScalingRules - element: - elements: - - label: - text: AppliesUpto (In Storage units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/scalingRules/items/properties/appliesUpto - type: input - - label: - text: Threshold (In %, Or In Storage Units) - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/scalingRules/items/properties/threshold - type: input - type: single-step-form - label: - text: ScalingRules - onChange: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/overseer/scalingRules|scalingRules - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/scalingRules - tableContents: - - inTableColumn: true - label: - text: AppliesUpto (In Storage units) - path: appliesUpto - type: value - typeOfValue: string - - inTableColumn: true - label: - text: Threshold (In %, Or In Storage Units) - path: threshold - type: value - typeOfValue: string - type: single-step-form-array - - label: - text: UpperBound - onChange: handleUnit|autoscalingKubedbComSolrAutoscaler/spec/storage/overseer/upperBound - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer/properties/upperBound - type: input - label: - text: Overseer - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/overseer - show_label: true - type: single-step-form - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected|storage - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected|storage - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/storage/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: OpsRequest Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: storage-autoscaler - title: steps.1.label -- form: - discriminator: - binding: - default: false - type: boolean - elements: - - computed: isBindingAlreadyOn - label: - text: Expose Database - onChange: addOrRemoveBinding - schema: - $ref: discriminator#/properties/binding - type: switch - type: single-step-form - id: binding - title: Gateway Binding -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + elements: + - type: block-layout + showLabels: false + loader: fetchTopologyMachines + elements: + # Coordinator + - type: block-layout + label: Coordinator + showLabels: true + if: + type: function + name: isTopology + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/compute/coordinator/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-coordinator-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|coordinator|min + loader: + name: getMachines|coordinator|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-coordinator-max + watcher: + func: onMachineChange|coordinator + paths: + - temp/properties/allowedMachine-coordinator-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-coordinator-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|coordinator|max + loader: + name: getMachines|coordinator|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-coordinator-min + watcher: + func: onMachineChange|coordinator + paths: + - temp/properties/allowedMachine-coordinator-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|coordinator + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/coordinator/properties/controlledResources + + # Data + - type: block-layout + label: Data + showLabels: true + if: + type: function + name: isTopology + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/compute/data/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-data-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|data|min + loader: + name: getMachines|data|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-data-max + watcher: + func: onMachineChange|data + paths: + - temp/properties/allowedMachine-data-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-data-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|data|max + loader: + name: getMachines|data|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-data-min + watcher: + func: onMachineChange|data + paths: + - temp/properties/allowedMachine-data-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|data + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/data/properties/controlledResources + + # Node + - type: block-layout + label: Node + showLabels: true + if: + type: function + name: isNotTopology + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/compute/node/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-node-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|node|min + loader: + name: getMachines|node|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-node-max + watcher: + func: onMachineChange|node + paths: + - temp/properties/allowedMachine-node-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-node-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|node|max + loader: + name: getMachines|node|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-node-min + watcher: + func: onMachineChange|node + paths: + - temp/properties/allowedMachine-node-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|node + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/node/properties/controlledResources + + # Overseer + - type: block-layout + label: Overseer + showLabels: true + if: + type: function + name: isTopology + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComSolrAutoscaler/spec/compute/overseer/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/podLifeTimeThreshold + - type: threshold-input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-overseer-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|overseer|min + loader: + name: getMachines|overseer|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-overseer-max + watcher: + func: onMachineChange|overseer + paths: + - temp/properties/allowedMachine-overseer-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-overseer-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|overseer|max + loader: + name: getMachines|overseer|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-overseer-min + watcher: + func: onMachineChange|overseer + paths: + - temp/properties/allowedMachine-overseer-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|overseer + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/overseer/properties/controlledResources + + # Node Topology + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select NodeTopology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: threshold-input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected|compute + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: threshold-input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected|compute + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + # Ops Request Options + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: time-picker + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComSolrAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + + - type: single-step-form + id: monitoring elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComSolr/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComSolr/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComSolr/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/agent + isHorizontal: true + options: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComSolr/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComSolr/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComSolr/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComSolr/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComSolr/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -type: multi-step-form + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComSolr/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + + - type: single-step-form + id: binding + label: Gateway Binding + elements: + - type: switch + label: Expose Database + schema: temp/properties/binding + fullwidth: true + init: + type: func + value: isBindingAlreadyOn + watcher: + func: addOrRemoveBinding + paths: + - temp/properties/binding \ No newline at end of file diff --git a/charts/kubedbcom-solr-editor/ui/functions.js b/charts/kubedbcom-solr-editor/ui/functions.js index 67b2ee7874..b14e94208c 100644 --- a/charts/kubedbcom-solr-editor/ui/functions.js +++ b/charts/kubedbcom-solr-editor/ui/functions.js @@ -1,61 +1,117 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + // ************************* common functions ******************************************** // eslint-disable-next-line no-empty-pattern -async function fetchJsons({ axios, itemCtx, setDiscriminatorValue }, discriminatorPath) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + setDiscriminatorValue('/allowedMachine-standalone-min', '') + setDiscriminatorValue('/allowedMachine-standalone-max', '') + setDiscriminatorValue('/allowedMachine-replicaSet-min', '') + setDiscriminatorValue('/allowedMachine-replicaSet-max', '') + setDiscriminatorValue('/allowedMachine-shard-min', '') + setDiscriminatorValue('/allowedMachine-shard-max', '') + setDiscriminatorValue('/allowedMachine-configServer-min', '') + setDiscriminatorValue('/allowedMachine-configServer-max', '') + setDiscriminatorValue('/allowedMachine-mongos-min', '') + setDiscriminatorValue('/allowedMachine-mongos-max', '') + + // compute + + let autoscaleType = '' + let dbDetails = {} + + function isConsole() { + const isKube = isKubedb() + + if (isKube) { + const dbName = storeGet('/route/params/name') || '' + commit('wizard/model$update', { + path: '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name', + value: dbName, + force: true, + }) + const operation = storeGet('/route/params/actions') || '' + if (operation.length) { + const splitOp = operation.split('-') + if (splitOp.length > 2) autoscaleType = splitOp[2] + } + const date = Math.floor(Date.now() / 1000) + const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + commit('wizard/model$update', { + path: '/metadata/name', + value: modifiedName, + force: true, + }) + const namespace = storeGet('/route/query/namespace') || '' + if (namespace) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: namespace, + force: true, + }) + } + } + + return !isKube } - if (discriminatorPath) { - setDiscriminatorValue(discriminatorPath, { - ui: ui.data || {}, - language: language.data || {}, - functions, - }) + function isKubedb() { + return !!storeGet('/route/params/actions') } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function showOpsRequestOptions() { + if (isKubedb() === true) return true + watchDependency('model#/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') + watchDependency('discriminator#/autoscalingType') + return ( + !!getValue(model, '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') && + !!getValue(discriminator, '/autoscalingType') + ) } -} -function disableLableChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} + async function getNamespaces() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) + + const resources = (resp && resp.data && resp.data.items) || [] -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } + + async function getDbs() { + watchDependency('model#/metadata/namespace') + const namespace = getValue(model, '/metadata/namespace') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/solrs`, { params: { filter: { items: { metadata: { name: null } } } }, }, @@ -63,3366 +119,830 @@ async function getResources({ axios, storeGet }, group, version, resource) { const resources = (resp && resp.data && resp.data.items) || [] - resources.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + return { + text: name, + value: name, + } }) - return resources - } catch (e) { - console.log(e) - return [] } -} -function isEqualToDiscriminatorPath( - { discriminator, getValue, watchDependency }, - value, - discriminatorPath, -) { - watchDependency('discriminator#' + discriminatorPath) - const discriminatorValue = getValue(discriminator, discriminatorPath) - return discriminatorValue === value -} - -function setValueFromModel({ getValue, model }, path) { - return getValue(model, path) -} - -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + async function getDbDetails() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = + storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' + const name = + storeGet('/route/params/name') || + getValue(model, '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') || + '' + + if (namespace && name) { + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/solrs/${name}`, + ) + dbDetails = resp.data || {} + setDiscriminatorValue('/dbDetails', true) + } catch (e) { + console.log(e) + } + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + commit('wizard/model$update', { + path: `/metadata/release/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/metadata/release/namespace`, + value: namespace, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name`, + value: name, + force: true, + }) + commit('wizard/model$update', { + path: `/resources/autoscalingKubedbComRedisAutoscaler/metadata/labels`, + value: dbDetails.metadata.labels, + force: true, }) + } + + function initMetadata() { + const dbName = + getValue(model, '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') || '' + const type = getValue(discriminator, '/autoscalingType') || '' + const date = Math.floor(Date.now() / 1000) + const resource = storeGet('/route/params/resource') + const scalingName = dbName ? dbName : resource + const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` + if (modifiedName) + commit('wizard/model$update', { + path: '/metadata/name', + value: modifiedName, + force: true, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + // delete the other type object from model + if (type === 'compute') + commit('wizard/model$delete', '/resources/autoscalingKubedbComSolrAutoscaler/spec/storage') + if (type === 'storage') + commit('wizard/model$delete', '/resources/autoscalingKubedbComSolrAutoscaler/spec/compute') } - return ans -} + function onNamespaceChange() { + const namespace = getValue(model, '/metadata/namespace') + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name', + ) + } + } -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function fetchNodeTopology() { + const owner = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` + try { + const resp = await axios.get(url) + const list = (resp && resp.data?.items) || [] + const mappedList = list.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return name + }) + return mappedList + } catch (e) { + console.log(e) + } + return [] + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + function isNodeTopologySelected(type) { + // watchDependency( + // `model#/resources/autoscalingKubedbComSolrAutoscaler/spec/${type}/nodeTopology/name`, + // ) + const nodeTopologyName = + getValue( + model, + `/resources/autoscalingKubedbComSolrAutoscaler/spec/${type}/nodeTopology/name`, + ) || '' + return !!nodeTopologyName.length + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, + function setControlledResources(type) { + const list = ['cpu', 'memory'] + const path = `/resources/autoscalingKubedbComSolrAutoscaler/spec/compute/${type}/controlledResources` + commit('wizard/model$update', { + path: path, + value: list, + force: true, }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return list } - return ans -} + function setTrigger(path) { + let value = getValue(model, `/resources/${path}`) + if (value) return value + return 'On' + } -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function setApplyToIfReady() { + return 'IfReady' } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + function setMetadata() { + const dbname = storeGet('/route/params/name') || '' + const namespace = storeGet('/route/query/namespace') || '' + if (mode === 'standalone-step') { + commit('wizard/model$update', { + path: '/metadata/release/name', + value: dbname, + force: true, + }) + commit('wizard/model$update', { + path: '/metadata/release/namespace', + value: namespace, + force: true, + }) } - }) -} + } -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + async function fetchTopologyMachines() { + const instance = hasAnnotations() + + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + if (instance) { + try { + const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` + const resp = await axios.get(url) + + const nodeGroups = resp.data?.spec?.nodeGroups || [] + setDiscriminatorValue('/topologyMachines', nodeGroups) + return nodeGroups + } catch (e) { + console.log(e) + return [] + } + } } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + function setAllowedMachine(type, minmax) { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComSolrAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} } - }) -} -function returnTrue() { - return true -} + const machine = parsedInstance[type] || '' + const mx = machine?.includes(',') ? machine.split(',')[1] : '' + const mn = machine?.includes(',') ? machine.split(',')[0] : '' -function returnStringYes() { - return 'yes' -} + if (minmax === 'min') return mn + else return mx + } -function isTopology({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComSolr/spec/topology') - const topo = getValue(model, '/resources/kubedbComSolr/spec/topology') + async function getMachines(type, minmax) { + watchDependency('discriminator#/topologyMachines') + const depends = minmax === 'min' ? 'max' : 'min' + const dependantPath = `/allowedMachine-${type}-${depends}` - return !!topo -} + watchDependency(`discriminator#${dependantPath}`) + const dependantMachine = getValue(discriminator, dependantPath) -function isNotTopology({ model, getValue, watchDependency }) { - return !isTopology({ model, getValue, watchDependency }) -} + const nodeGroups = getValue(discriminator, '/topologyMachines') || [] -function isDiscriminatorEqualTo( - { discriminator, getValue, watchDependency }, - discriminatorPath, - value, -) { - watchDependency('discriminator#' + discriminatorPath) - const pathValue = getValue(discriminator, discriminatorPath) + const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - return value === pathValue -} + const machines = nodeGroups?.map((item) => { + const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` + const text = item.topologyValue + return { text, subText, value: item.topologyValue } + }) -function isAuthPluginNotSearchGuard({ discriminator, getValue, watchDependency, commit }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') - const pathValue = getValue(discriminator, '/selectedVersionAuthPlugin') + const filteredMachine = machines?.filter((item, ind) => + minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, + ) - if (!pathValue) return false + return dependantIndex === -1 ? machines : filteredMachine + } - const ret = pathValue !== 'SearchGuard' && pathValue !== '' + function hasAnnotations(type) { + const annotations = getValue( + model, + '/resources/autoscalingKubedbComSolrAutoscaler/metadata/annotations', + ) + const instance = annotations['kubernetes.io/instance-type'] - if (!ret) { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/dataWarm') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/dataHot') + return !!instance } - return ret -} -// required for outer form section. where discriminator can not be saved -async function showInternalUsersAndRolesMapping({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - commit, -}) { - watchDependency('model#/resources/kubedbComSolr/spec/disableSecurity') - watchDependency('model#/resources/kubedbComSolr/spec/version') - - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) + function hasNoAnnotations() { + return !hasAnnotations() + } - const ret = - (dist === 'OpenDistro' || dist === 'SearchGuard') && - isSecurityEnabled({ model, getValue, watchDependency }) + function onMachineChange(type) { + const annoPath = '/resources/autoscalingKubedbComSolrAutoscaler/metadata/annotations' + const annotations = getValue(model, annoPath) + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } - if (ret) { - commit('wizard/showSteps$update', { - stepId: 'internal-users', - show: true, - }) + const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) + const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) + const minMaxMachine = `${minMachine},${maxMachine}` - commit('wizard/showSteps$update', { - stepId: 'roles-mapping', - show: true, - }) - } else { - commit('wizard/showSteps$update', { - stepId: 'internal-users', - show: false, - }) + parsedInstance[type] = minMaxMachine + const instanceString = JSON.stringify(parsedInstance) + annotations['kubernetes.io/instance-type'] = instanceString - commit('wizard/showSteps$update', { - stepId: 'roles-mapping', - show: false, - }) + const machines = getValue(discriminator, `/topologyMachines`) || [] + const minMachineObj = machines.find((item) => item.topologyValue === minMachine) + const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) + const minMachineAllocatable = minMachineObj?.allocatable + const maxMachineAllocatable = maxMachineObj?.allocatable + const allowedPath = `/resources/autoscalingKubedbComSolrAutoscaler/spec/compute/${type}` + + if (minMachine && maxMachine && instance !== instanceString) { + commit('wizard/model$update', { + path: `${allowedPath}/maxAllowed`, + value: maxMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: `${allowedPath}/minAllowed`, + value: minMachineAllocatable, + force: true, + }) + commit('wizard/model$update', { + path: annoPath, + value: annotations, + force: true, + }) + } } - return ret -} -// required for outer form section. where discriminator can not be saved -async function showSecureCustomConfig({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - commit, -}) { - watchDependency('model#/resources/kubedbComSolr/spec/version') - - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) + // storage - const ret = dist === 'X-Pack' + function handleUnit(path, type = 'bound') { + let value = getValue(model, `/resources/${path}`) + if (type === 'scalingRules') { + const updatedValue = [] + value?.forEach((ele) => { + let appliesUpto = ele['appliesUpto'] + let threshold = ele['threshold'] + if (appliesUpto && !isNaN(appliesUpto)) { + appliesUpto += 'Gi' + } + if (!isNaN(threshold)) { + threshold += 'pc' + } + updatedValue.push({ threshold, appliesUpto }) + }) + if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { + commit('wizard/model$update', { + path: `/resources/${path}`, + value: updatedValue, + force: true, + }) + } + } else { + if (!isNaN(value)) { + value += 'Gi' + commit('wizard/model$update', { + path: `/resources/${path}`, + value: value, + force: true, + }) + } + } + } - if (ret) { - commit('wizard/showSteps$update', { - stepId: 'secure-custom-config', - show: true, - }) - } else { - commit('wizard/showSteps$update', { - stepId: 'secure-custom-config', - show: false, - }) + /****** Monitoring *********/ - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/secureConfigSecret') - commit('wizard/model$delete', '/resources/secret_secure_config') + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value } - return ret -} -// ************************* Basic Info ********************************************** + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getSolrVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, authPlugin: null }, - }, - }, - } + const resources = (resp && resp.data && resp.data.items) || [] - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } - const resources = (resp && resp.data && resp.data.items) || [] + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - // keep only non deprecated versions - const filteredSolrVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - filteredSolrVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredSolrVersions -} + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) -function isSecurityEnabled({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComSolr/spec/disableSecurity') - const value = getValue(model, '/resources/kubedbComSolr/spec/disableSecurity') - return !value -} + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } -function onDisableSecurityChange({ model, getValue, commit }) { - const disableSecurity = getValue(model, '/resources/kubedbComSolr/spec/disableSecurity') + return ans + } - if (disableSecurity) { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/authSecret') - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/internalUsers') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/rolesMapping') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/tls') + function removeCertificatesOfAliases(aliasesToRemove) { + const certificates = getValue(model, '/resources/kubedbComSolr/spec/tls/certificates') || [] + const updatedCertificates = certificates.filter((item) => !aliasesToRemove.includes(item.alias)) + commit('wizard/model$update', { + path: '/resources/kubedbComSolr/spec/tls/certificates', + value: updatedCertificates, + force: true, + }) } -} -async function onVersionChange({ - model, - getValue, - watchDependency, - axios, - storeGet, - commit, - setDiscriminatorValue, -}) { - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - - const isOpenDistro = dist === 'OpenDistro' - const isSearchGuard = dist === 'SearchGuard' - const isXpack = dist === 'X-Pack' - - if (!isOpenDistro && !isSearchGuard) { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/internalUsers') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/rolesMapping') - if (isXpack) { - removeCertificatesOfAliases({ model, getValue, commit }, ['admin']) - } - } else { - if (!isOpenDistro) { - const internalUsers = getValue(model, '/resources/kubedbComSolr/spec/internalUsers') - - if (internalUsers) { - Object.keys(internalUsers).map((key) => { - if (internalUsers[key]?.opendistroSecurityRoles) - delete internalUsers[key]?.opendistroSecurityRoles - }) - } + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/internalUsers', - value: internalUsers, + path: '/resources/kubedbComSolr/spec/monitor', + value: {}, force: true, }) - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/dataHot') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/dataWarm') + } else { + commit('wizard/model$delete', '/resources/kubedbComSolr/spec/monitor') } - if (!isSearchGuard) { - const internalUsers = getValue(model, '/resources/kubedbComSolr/spec/internalUsers') - if (internalUsers) { - Object.keys(internalUsers).map((key) => { - if (internalUsers[key]?.searchGuardRoles) delete internalUsers[key]?.searchGuardRoles - }) - } + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', + force: true, + }) + } + + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/internalUsers', - value: internalUsers, + path: '/resources/kubedbComSolr/spec/monitor/prometheus/exporter', + value: {}, force: true, }) - } - - if (!isXpack) { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/dataCold') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/dataContent') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/dataFrozen') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/ml') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology/transform') + } else { + commit('wizard/model$delete', '/resources/kubedbComSolr/spec/monitor/prometheus/exporter') } } -} - -function onEnableSSLChange({ model, getValue, commit }) { - const enabelSSL = getValue(model, '/resources/kubedbComSolr/spec/enableSSL') - if (enabelSSL === false) { - removeCertificatesOfAliases({ model, getValue, commit }, [ - 'http', - 'archiver', - 'metrics-exporter', - ]) + function isValueExistInModel(path) { + const modelValue = getValue(model, path) + return !!modelValue } -} -function removeCertificatesOfAliases({ model, getValue, commit }, aliasesToRemove) { - const certificates = getValue(model, '/resources/kubedbComSolr/spec/tls/certificates') || [] - const updatedCertificates = certificates.filter((item) => !aliasesToRemove.includes(item.alias)) - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/tls/certificates', - value: updatedCertificates, - force: true, - }) -} + // function onNamespaceChange({ commit, model, getValue }) { + // const namespace = getValue(model, '/metadata/release/namespace') + // const agent = getValue(model, '/resources/kubedbComSolr/spec/monitor/agent') + // if (agent === 'prometheus.io') { + // commit('wizard/model$update', { + // path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', + // value: [namespace], + // force: true, + // }) + // } + // } -/************************************* Database Secret Section ********************************************/ + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComSolr/spec/metadata/labels') -function getCreateAuthSecret({ model, getValue }) { - const authSecret = getValue(model, '/resources/kubedbComSolr/spec/authSecret') + const agent = getValue(model, '/resources/kubedbComSolr/spec/monitor/agent') - return !authSecret -} + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) + } + } -function showExistingSecretSection({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/createAuthSecret') + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComSolr/spec/monitor/agent') - const hasAuthSecretName = getValue(discriminator, '/createAuthSecret') - return !hasAuthSecretName -} + if (!agent) { + removeCertificatesOfAliases(['metrics-exporter']) + } -function showPasswordSection({ getValue, watchDependency, discriminator }) { - return !showExistingSecretSection({ - getValue, - watchDependency, - discriminator, - }) -} + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) -function setAuthSecretPassword({ model, getValue, watchDependency, discriminator, commit }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } + } + + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` + + const isKube = !!storeGet('/route/params/actions') + + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/solropsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` + } + + function onNamespaceChange() { + const namespace = getValue(model, 'onNamespaceChange') + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name', + ) + } + } - const dist = getValue(discriminator, '/selectedVersionAuthPlugin') - if (dist) { - if (dist === 'X-Pack') { - const encodedPassword = getValue(model, '/resources/secret_elastic_cred/data/password') - commit('wizard/model$delete', '/resources/secret_admin_cred') - return encodedPassword ? decodePassword({}, encodedPassword) : '' + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' } else { - const encodedPassword = getValue(model, '/resources/secret_admin_cred/data/password') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - return encodedPassword ? decodePassword({}, encodedPassword) : '' + return 'input' } } -} -function onAuthSecretPasswordChange({ getValue, discriminator, commit }) { - const stringPassword = getValue(discriminator, '/password') - const dist = getValue(discriminator, '/selectedVersionAuthPlugin') + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } + + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } - if (dist) { - if (stringPassword) { - if (dist === 'X-Pack') { + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) commit('wizard/model$update', { - path: '/resources/secret_elastic_cred/data/password', - value: encodePassword({}, stringPassword), - force: true, + path: 'temp/valueFrom/configMapKeyRef', + value: true, }) + if (isSecretTypeValueFrom()) commit('wizard/model$update', { - path: '/resources/secret_elastic_cred/data/username', - value: encodePassword({}, 'elastic'), - force: true, + path: 'temp/valueFrom/secretKeyRef', + value: true, }) - commit('wizard/model$delete', '/resources/secret_admin_cred') - } else { + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) commit('wizard/model$update', { - path: '/resources/secret_admin_cred/data/password', - value: encodePassword({}, stringPassword), - force: true, + path: 'temp/valueFrom/secretKeyRef', + value: false, }) + if (isConfigMapTypeValueFrom()) commit('wizard/model$update', { - path: '/resources/secret_admin_cred/data/username', - value: encodePassword({}, 'admin'), - force: true, + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, }) - commit('wizard/model$delete', '/resources/secret_elastic_cred') - } - } else { - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - } - } -} - -// eslint-disable-next-line no-empty-pattern -function encodePassword({}, value) { - return btoa(value) -} - -// eslint-disable-next-line no-empty-pattern -function decodePassword({}, value) { - return atob(value) -} - -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/authSecret') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/resources/secret_admin_cred') - commit('wizard/model$delete', '/resources/secret_elastic_cred') - } -} - -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] - - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets - } catch (e) { - console.log(e) - return [] - } -} - -function showSecretSection({ model, getValue, watchDependency, storeGet }) { - const steps = storeGet('/wizard/configureOptions') - - return ( - !steps.includes('internal-users') && isSecurityEnabled({ model, getValue, watchDependency }) - ) -} - -// ********************* Database Mode *********************** -function isNotCombinedMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - return mode !== 'Combined' -} - -function setDatabaseMode({ model, getValue }) { - isTopology = getValue(model, '/resources/kubedbComSolr/spec/topology') - if (isTopology) { - return 'Dedicated' - } else { - return 'Combined' - } -} - -let storageClassList = [] -async function getStorageClassNames( - { axios, storeGet, commit, setDiscriminatorValue, getValue, model }, - path, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/storage.k8s.io/v1/storageclasses`, - { - params: { - filter: { items: { metadata: { name: null, annotations: null } } }, - }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - - if (!path) { - setDiscriminatorValue('/storageClasses', resources) - } - storageClassList = resources - const initialStorageClass = getValue(model, path) - if (!initialStorageClass) setStorageClass({ model, getValue, commit }, path) - return resources -} - -function setStorageClass({ model, getValue, commit }, path) { - const deletionPolicy = getValue(model, 'resources/kubedbComSolr/spec/deletionPolicy') || '' - let storageClass = getValue(model, path) || '' - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.metadata?.name?.endsWith(suffix) - }) - - const retainClassList = storageClassList.filter((item) => { - return item.metadata?.name?.endsWith(suffix) - }) - - const defaultSimpleList = simpleClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - const defaultRetainList = retainClassList.filter((item) => { - return ( - item.metadata && - item.metadata.annotations && - item.metadata.annotations['storageclass.kubernetes.io/is-default-class'] - ) - }) - - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - if (simpleClassList.length > 1) { - const found = defaultSimpleList.length ? defaultSimpleList[0] : simpleClassList[0] - storageClass = found.value - } else if (simpleClassList.length === 1) { - storageClass = simpleClassList[0]?.value - } else { - const found = defaultRetainList.length - ? defaultRetainList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } else { - if (retainClassList.length > 1) { - const found = defaultRetainList.length ? defaultRetainList[0] : retainClassList[0] - storageClass = found.value - } else if (retainClassList.length === 1) { - storageClass = retainClassList[0]?.value - } else { - const found = defaultSimpleList.length - ? defaultSimpleList[0].value - : storageClassList.length - ? storageClassList[0].value - : '' - storageClass = found - } - } - - if (storageClass && path) { - commit('wizard/model$update', { - path: path, - value: storageClass, - force: true, - }) - } -} - -function deleteDatabaseModePath({ discriminator, getValue, commit }) { - const mode = getValue(discriminator, '/activeDatabaseMode') - if (mode === 'Dedicated') { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/replicas') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/storage') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/maxUnavailable') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/podTemplate') - } else if (mode === 'Combined') { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/topology') - } -} - -function isEqualToDatabaseMode({ getValue, watchDependency, discriminator }, value) { - watchDependency('discriminator#/activeDatabaseMode') - const mode = getValue(discriminator, '/activeDatabaseMode') - - return mode === value -} - -function getMaxUnavailableOptions({ model, getValue, watchDependency, commit, elementUi }, path) { - let prefixPath - if (path) { - prefixPath = path - } else { - const { $ref } = elementUi.schema || {} - const replacedPath = ($ref || '').replace( - 'schema#/properties/resources/properties/kubedbComSolr/properties/spec/properties/topology/properties/', - '', - ) - const dyn = replacedPath.split('/').shift() - prefixPath = `/resources/kubedbComSolr/spec/topology/${dyn}` - } - - watchDependency(`model#${prefixPath}/replicas`) - - const replicas = getValue(model, `${prefixPath}/replicas`) - const maxUnavailable = getValue(model, `${prefixPath}/maxUnavailable`) - - if (maxUnavailable > replicas) { - commit('wizard/model$update', { - path: `${prefixPath}/maxUnavailable`, - value: replicas, - force: true, - }) - } - - const options = [] - - for (let i = 0; i <= Math.min(replicas, 1000); i++) { - options.push(i) - } - return options -} - -function getStorageClassNamesFromDiscriminator( - { model, discriminator, getValue, watchDependency, commit }, - path, -) { - watchDependency('discriminator#/storageClasses') - const options = getValue(discriminator, '/storageClasses') || [] - - setStorageClass({ model, getValue, commit }, path) - - return options -} - -async function getSelectedVersionAuthPlugin( - { model, getValue, watchDependency, axios, storeGet, setDiscriminatorValue }, - path, -) { - watchDependency('model#/resources/kubedbComSolr/spec/version') - const version = getValue(model, '/resources/kubedbComSolr/spec/version') || '' - - const elasticVersions = await getSolrVersions( - { axios, storeGet }, - 'catalog.kubedb.com', - 'v1alpha1', - 'solrversions', - ) - - const selectedVersion = elasticVersions?.find((item) => item.value === version) - - const ret = selectedVersion?.spec?.authPlugin || '' - - if (path) { - setDiscriminatorValue(path, ret) - } - - return ret -} - -function onNodeSwitchFalse({ elementSchema, commit }) { - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - commit('wizard/model$delete', `/resources/kubedbComSolr/spec/topology/${node}`) -} - -function hasTopologyNode({ model, getValue, itemCtx }) { - const nodeValue = getValue(model, `/resources/kubedbComSolr/spec/topology/${itemCtx}`) - - return !nodeValue -} - -function hideNode({ itemCtx, discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/selectedVersionAuthPlugin') - const authPlugin = getValue(discriminator, '/selectedVersionAuthPlugin') - - let hiddenNodes = ['coordinating'] - - if (authPlugin === 'OpenDistro') { - hiddenNodes = ['coordinating', 'ml', 'dataCold', 'dataFrozen', 'dataContent', 'transform'] - } else if (authPlugin === 'SearchGuard') { - hiddenNodes = [ - 'coordinating', - 'ml', - 'dataWarm', - 'dataHot', - 'dataCold', - 'dataFrozen', - 'dataContent', - 'transform', - ] - } - - const verd = hiddenNodes.includes(itemCtx) - return verd -} - -function setInitialStatusFalse({ elementSchema }) { - const disableNodes = ['master', 'data', 'ingest'] - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - return !disableNodes.includes(node) -} - -function disableNode({ elementSchema }) { - const disableNodes = ['master', 'data', 'ingest'] - const { $ref } = elementSchema || {} - const node = ($ref || '').split('/').pop() - return disableNodes.includes(node) -} - -// ************************** Internal Users ******************************** - -const defaultUsers = [ - 'admin', - 'kibanaro', - 'kibanaserver', - 'logstash', - 'readall', - 'snapshotrestore', - 'metrics_exporter', -] - -function onInternalUsersChange({ discriminator, getValue, commit }) { - const users = getValue(discriminator, '/internalUsers') - - const internalUsers = {} - - if (users) { - users.forEach((item) => { - const { username, createCred, secretName, password, ...obj } = item - if (createCred === 'no') { - obj.secretName = secretName - commit('wizard/model$delete', `/resources/secret_${username}_cred`) - } else if (createCred === 'yes') { - if (password) { - commit('wizard/model$update', { - path: `/resources/secret_${username}_cred/data/password`, - value: encodePassword({}, password), - force: true, - }) - commit('wizard/model$update', { - path: `/resources/secret_${username}_cred/data/username`, - value: encodePassword({}, username), - force: true, - }) - } else { - commit('wizard/model$delete', `/resources/secret_${username}_cred`) - } - } - internalUsers[username] = obj - }) - } - - if (Object.keys(internalUsers).length) { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/internalUsers', - value: internalUsers, - force: true, - }) - } else { - // on initial call discriminator value is undefined - // to ignore model$delete for this case, - // users value checking is required, - // model$delete will be executed only if users value is not falsy value (empty array) - // and internalUsers is emptyObject - if (users) commit('wizard/model$delete', '/resources/kubedbComSolr/spec/internalUsers') - } -} - -function setInternalUsers({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/kubedbComSolr/spec/internalUsers') - const internalUsers = getValue(model, '/resources/kubedbComSolr/spec/internalUsers') - - const users = [] - - for (const item in internalUsers) { - internalUsers[item].username = item - const encodedPassword = getValue(model, `/resources/secret_${item}_cred/data/password`) - if (internalUsers[item].secretName) { - internalUsers[item].createCred = 'no' - } else { - if (encodedPassword) { - internalUsers[item].password = decodePassword({}, encodedPassword) - } - internalUsers[item].createCred = 'yes' - } - users.push(internalUsers[item]) - } - - setDiscriminatorValue('/internalUsers', users) - - return users -} - -function validateNewUser({ itemCtx }) { - if (defaultUsers.includes(itemCtx.username) && itemCtx.isCreate) { - return { isInvalid: true, message: "Can't use this username" } - } - return {} -} - -function disableUsername({ rootModel }) { - return defaultUsers.includes(rootModel && rootModel.username) -} - -function disableUserEdit({ itemCtx }) { - if (defaultUsers.includes(itemCtx.username)) { - return { isEditDisabled: false, isDeleteDisabled: true } - } - return {} -} - -async function isAuthPluginEqualTo( - { model, getValue, watchDependency, axios, storeGet, setDiscriminatorValue }, - authPlugin, -) { - const dist = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - return dist === authPlugin -} - -// internal user cred -function showPasswordCredSection({ rootModel, getValue, watchDependency }) { - watchDependency('rootModel#/createCred') - const createCred = getValue(rootModel, '/createCred') - - return createCred === 'yes' -} - -function showExistingCredSection({ rootModel, getValue, watchDependency }) { - return !showPasswordCredSection({ rootModel, getValue, watchDependency }) -} - -function disableRoleDeletion({ itemCtx, rootModel }) { - return itemCtx === 'admin' && rootModel.username === 'admin' -} - -// ************************** Roles Mapping ******************************** - -const defaultRoles = ['readall_and_monitor'] - -function onRolesMappingChange({ discriminator, getValue, commit }) { - const roles = getValue(discriminator, '/rolesMapping') - - const rolesMapping = {} - - if (roles) { - roles.forEach((item) => { - const { roleName, ...obj } = item - rolesMapping[roleName] = obj - }) - } - - if (Object.keys(rolesMapping).length) { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/rolesMapping', - value: rolesMapping, - force: true, - }) - } else { - // on initial call discriminator value is undefined - // to ignore model$delete for this case, - // roles value checking is required, - // model$delete will be executed only if roles value is not falsy value (empty array) - // and rolesMapping is emptyObject - if (roles) commit('wizard/model$delete', '/resources/kubedbComSolr/spec/rolesMapping') - } -} - -function setRolesMapping({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/kubedbComSolr/spec/rolesMapping') - const rolesMapping = getValue(model, '/resources/kubedbComSolr/spec/rolesMapping') - - const roles = [] - - for (const item in rolesMapping) { - rolesMapping[item].roleName = item - roles.push(rolesMapping[item]) - } - - setDiscriminatorValue('/rolesMapping', roles) - - return roles -} - -function disableRolesEdit({ itemCtx }) { - if (defaultRoles.includes(itemCtx.roleName)) { - return { isEditDisabled: false, isDeleteDisabled: true } - } - return {} -} - -function disableRoleName({ rootModel }) { - return defaultRoles.includes(rootModel && rootModel.roleName) -} - -function validateNewRole({ itemCtx }) { - if (defaultRoles.includes(itemCtx.roleName) && itemCtx.isCreate) { - return { isInvalid: true, message: "Can't use this role name" } - } - return {} -} - -function getInternalUsers({ model, getValue, watchDependency }) { - watchDependency('model#/resources/kubedbComSolr/spec/internalUsers') - const internalUsers = getValue(model, '/resources/kubedbComSolr/spec/internalUsers') - - return Object.keys(internalUsers) -} - -function disableUserDeletion({ itemCtx, rootModel }) { - return itemCtx.value === 'metrics_exporter' && rootModel.roleName === 'readall_and_monitor' -} - -// ************************* Kernel Settings ********************************* - -function onCustomizeKernelSettingChange({ discriminator, getValue, commit }) { - const customizeKernelSettings = getValue(discriminator, '/customizeKernelSettings') - - if (customizeKernelSettings === 'no') { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/kernelSettings') - } else if (customizeKernelSettings === 'disable') { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/kernelSettings', - value: {}, - force: true, - }) - } -} - -// ************************** TLS ******************************************* - -function setApiGroup() { - return 'cert-manager.io' -} - -function setApiGroupEdit({ model, getValue }) { - const kind = getValue(model, '/resources/kubedbComSolr/spec/tls/issuerRef/kind') - const name = getValue(model, '/resources/kubedbComSolr/spec/tls/issuerRef/name') - return kind && name ? 'cert-manager.io' : '' -} - -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/resources/kubedbComSolr/spec/tls/issuerRef/apiGroup') - watchDependency('model#/resources/kubedbComSolr/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/release/namespace') - const apiGroup = getValue(model, '/resources/kubedbComSolr/spec/tls/issuerRef/apiGroup') - const kind = getValue(model, '/resources/kubedbComSolr/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/release/namespace') - - let url - if (kind === 'Issuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/namespaces/${namespace}/issuers` - } else if (kind === 'ClusterIssuer') { - url = `/clusters/${owner}/${cluster}/proxy/${apiGroup}/v1/clusterissuers` - } - - try { - const resp = await axios.get(url) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } -} - -async function hasIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await getIssuerRefsName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !!(resp && resp.length) -} - -async function hasNoIssuerRefName({ axios, storeGet, getValue, model, watchDependency }) { - const resp = await hasIssuerRefName({ - axios, - storeGet, - getValue, - model, - watchDependency, - }) - - return !resp -} - -function setClusterAuthMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComSolr/spec/clusterAuthMode') - return val || 'x509' -} - -function setSSLMode({ model, getValue }) { - const val = getValue(model, '/resources/kubedbComSolr/spec/sslMode') - return val || 'requireSSL' -} - -function showTlsConfigureSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configureTLS') - const configureStatus = getValue(discriminator, '/configureTLS') - return configureStatus -} - -function onTlsConfigureChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/configureTLS') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/tls', - value: { issuerRef: {}, certificates: [] }, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/tls') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/clusterAuthMode') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/sslMode') - } -} - -async function showTlsRecommendation({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/issuers` - - try { - await axios.get(url, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - return false - } catch (err) { - // if any error response status is 404 or not - if (err.response && err.response.status === 404) { - resp = false - } - console.log(err) - return true - } -} - -async function getAliasOptions({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, -}) { - watchDependency('model#/resources/kubedbComSolr/spec/enableSSL') - watchDependency('model#/resources/kubedbComSolr/spec/monitor') - - const enableSSL = getValue(model, '/resources/kubedbComSolr/spec/enableSSL') - const monitor = getValue(model, '/resources/kubedbComSolr/spec/monitor') - const authPlugin = await getSelectedVersionAuthPlugin({ - model, - getValue, - watchDependency, - axios, - storeGet, - setDiscriminatorValue, - }) - - // always include transport cert alias - const aliases = ['transport'] - - if (authPlugin !== 'X-Pack') { - aliases.push('admin') - } - - if (enableSSL) { - aliases.push('http') - aliases.push('archiver') - if (monitor) { - aliases.push('metrics-exporter') - } - } - - return aliases -} - -/****** Monitoring *********/ - -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} - -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/monitor', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/monitor') - } - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} - -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} - -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/monitor/prometheus/exporter', - value: {}, - force: true, - }) - } else { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/monitor/prometheus/exporter') - } -} - -// ********************************* Initialization & Backup ************************************* -const stashAppscodeComRestoreSession_init = { - spec: { - repository: { - name: '', - }, - rules: [ - { - snapshots: ['latest'], - }, - ], - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} -const initScript = { - scriptPath: '', - secret: { - secretName: '', - }, -} -const stashAppscodeComRepository_init_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const stashAppscodeComRepository_repo = { - spec: { - backend: { - gcs: { - bucket: '', - prefix: '', - }, - storageSecretName: '', - }, - }, -} -const restoreSessionInitRunTimeSettings = { - container: { - resources: { - requests: { - cpu: '', - memory: '', - }, - limits: { - cpu: '', - memory: '', - }, - }, - nice: { - adjustment: null, - }, - ionice: { - class: null, - classData: null, - }, - securityContext: { - privileged: false, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - env: [], - envFrom: [], - }, - pod: { - serviceAccountName: '', - imagePullSecrets: [], - securityContext: { - fsGroup: null, - runAsNonRoot: false, - runAsUser: null, - runAsGroup: null, - seLinuxOptions: { - level: '', - role: '', - type: '', - user: '', - }, - }, - }, -} - -const stashAppscodeComBackupConfiguration = { - spec: { - repository: { - name: '', - }, - retentionPolicy: { - keepLast: 5, - name: 'keep-last-5', - prune: true, - }, - schedule: '*/5 * * * *', - target: { - ref: { - apiVersion: 'appcatalog.appscode.com/v1alpha1', - kind: 'AppBinding', - name: '', - }, - }, - }, -} - -function disableInitializationSection({ model, getValue, watchDependency }) { - const initialized = getValue(model, '/resources/kubedbComSolr/spec/init/initialized') - watchDependency('model#/resources/kubedbComSolr/spec/init/initialized') - return !!initialized -} - -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} - -function initPrePopulateDatabase({ getValue, model }) { - const waitForInitialRestore = getValue( - model, - '/resources/kubedbComSolr/spec/init/waitForInitialRestore', - ) - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - const script = getValue(model, '/resources/kubedbComSolr/spec/init/script') - - return waitForInitialRestore || !!stashAppscodeComRestoreSession_init || !!script ? 'yes' : 'no' -} - -function onPrePopulateDatabaseChange({ commit, getValue, discriminator, model }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - if (prePopulateDatabase === 'no') { - // delete related properties - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/init/waitForInitialRestore', - value: false, - }) - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/init/script') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else { - const dbName = getValue(model, '/metadata/release/name') - // set stashAppscodeComRestoreSession_init if it doesn't exist - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -function initDataSource({ getValue, model }) { - const script = getValue(model, '/resources/kubedbComSolr/spec/init/script') - const stashAppscodeComRestoreSession_init = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init', - ) - - if (script) return 'script' - else if (stashAppscodeComRestoreSession_init) return 'stashBackup' - else return undefined -} - -function onDataSourceChange({ commit, getValue, discriminator, model }) { - const dataSource = getValue(discriminator, '/dataSource') - - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/init/waitForInitialRestore', - value: dataSource === 'stashBackup', - force: true, - }) - - if (dataSource === 'script') { - commit('wizard/model$delete', '/resources/stashAppscodeComRestoreSession_init') - - // create a new script if there is no script property - if (!valueExists(model, getValue, '/resources/kubedbComSolr/spec/init/script')) - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/init/script', - value: initScript, - }) - } else if (dataSource === 'stashBackup') { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/init/script') - - // create a new stashAppscodeComRestoreSession_init if there is no stashAppscodeComRestoreSession_init property - if (!valueExists(model, getValue, '/resources/stashAppscodeComRestoreSession_init')) { - const dbName = getValue(model, '/metadata/release/name') - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init', - value: stashAppscodeComRestoreSession_init, - }) - - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// // for script -function initVolumeType({ getValue, model }) { - const configMap = getValue(model, '/resources/kubedbComSolr/spec/init/script/configMap/name') - const secret = getValue(model, '/resources/kubedbComSolr/spec/init/script/secret/secretName') - - if (configMap) return 'configMap' - else if (secret) return 'secret' - else return undefined -} - -function onVolumeTypeChange({ commit, getValue, discriminator, model }) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - if (sourceVolumeType === 'configMap') { - // add configMap object and delete secret object - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/init/script/secret') - - if (!valueExists(model, getValue, '/resources/kubedbComSolr/spec/init/script/configMap')) { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/init/script/configMap', - value: { - name: '', - }, - }) - } - } else if (sourceVolumeType === 'secret') { - // delete configMap object and add secret object - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/init/script/configMap') - - if (!valueExists(model, getValue, '/resources/kubedbComSolr/spec/init/script/secret')) { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/init/script/secret', - value: { - secretName: '', - }, - }) - } - } -} - -function showInitializationForm({ getValue, discriminator, watchDependency }) { - const prePopulateDatabase = getValue(discriminator, '/prePopulateDatabase') - watchDependency('discriminator#/prePopulateDatabase') - return prePopulateDatabase === 'yes' -} - -function showScriptOrStashForm({ getValue, discriminator, watchDependency }, value) { - const dataSource = getValue(discriminator, '/dataSource') - watchDependency('discriminator#/dataSource') - return dataSource === value -} - -function showConfigMapOrSecretName({ getValue, discriminator, watchDependency }, value) { - const sourceVolumeType = getValue(discriminator, '/sourceVolumeType') - watchDependency('discriminator#/sourceVolumeType') - return sourceVolumeType === value -} - -// for stash backup -function initializeNamespace({ getValue, model }) { - const namespace = getValue(model, '/metadata/release/namespace') - return namespace -} - -function showRepositorySelectOrCreate({ getValue, discriminator, watchDependency }, value) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - return repositoryChoise === value -} - -function onInitRepositoryChoiseChange({ getValue, discriminator, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - if (repositoryChoise === 'select') { - // delete stashAppscodeComRepository_init_repo from model - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_init_repo') - } else if (repositoryChoise === 'create') { - // add stashAppscodeComRepository_init_repo to model - commit('wizard/model$update', { - path: 'resources/stashAppscodeComRepository_init_repo', - value: stashAppscodeComRepository_init_repo, - }) - - const repositoryName = `${getValue(model, '/metadata/release/name')}-init-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: repositoryName, - }) - } -} - -function initCustomizeRestoreJobRuntimeSettings({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function initCustomizeRestoreJobRuntimeSettingsForBackup({ getValue, model }) { - const runtimeSettings = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - if (runtimeSettings) return 'yes' - else return 'no' -} - -function onCustomizeRestoreJobRuntimeSettingsChange({ commit, getValue, discriminator, model }) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/runtimeSettings', - value: restoreSessionInitRunTimeSettings, - }) - } - } -} - -function onCustomizeRestoreJobRuntimeSettingsChangeForBackup({ - commit, - getValue, - discriminator, - model, -}) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - if (customizeRestoreJobRuntimeSettings === 'no') { - commit( - 'wizard/model$delete', - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - } else if (customizeRestoreJobRuntimeSettings === 'yes') { - if ( - !valueExists( - model, - getValue, - '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - ) - ) { - // set new value - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/runtimeSettings', - value: {}, - force: true, - }) - } - } -} - -function showRuntimeForm({ discriminator, getValue, watchDependency }, value) { - const customizeRestoreJobRuntimeSettings = getValue( - discriminator, - '/customizeRestoreJobRuntimeSettings', - ) - watchDependency('discriminator#/customizeRestoreJobRuntimeSettings') - return customizeRestoreJobRuntimeSettings === value -} - -async function getImagePullSecrets({ getValue, model, watchDependency, axios, storeGet }) { - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group: 'core', - version: 'v1', - resource: 'secrets', - }) - - resources = resources.filter((item) => { - const validType = ['kubernetes.io/dockerconfigjson'] - return validType.includes(item.type) - }) - - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: { name: name }, - } - }) -} - -// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// FOR Backup Configuration - -// schedule bakcup - -function getBackupConfigsAndAnnotations(getValue, model) { - const stashAppscodeComBackupConfiguration = getValue( - model, - '/resources/stashAppscodeComBackupConfiguration', - ) - const kubedbComSolrAnnotations = - getValue(model, '/resources/kubedbComSolr/metadata/annotations') || {} - - const isBluePrint = Object.keys(kubedbComSolrAnnotations).some( - (k) => - k === 'stash.appscode.com/backup-blueprint' || - k === 'stash.appscode.com/schedule' || - k.startsWith('params.stash.appscode.com/'), - ) - - return { - stashAppscodeComBackupConfiguration, - isBluePrint, - } -} - -function deleteKubedbComSolrDbAnnotation(getValue, model, commit) { - const annotations = getValue(model, '/resources/kubedbComSolr/metadata/annotations') || {} - const filteredKeyList = - Object.keys(annotations).filter( - (k) => - k !== 'stash.appscode.com/backup-blueprint' && - k !== 'stash.appscode.com/schedule' && - !k.startsWith('params.stash.appscode.com/'), - ) || [] - const filteredAnnotations = {} - filteredKeyList.forEach((k) => { - filteredAnnotations[k] = annotations[k] - }) - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/metadata/annotations', - value: filteredAnnotations, - }) -} - -function addKubedbComSolrDbAnnotation(getValue, model, commit, key, value, force) { - const annotations = getValue(model, '/resources/kubedbComSolr/metadata/annotations') || {} - - if (annotations[key] === undefined) { - annotations[key] = value - } else if (force) { - annotations[key] = value - } - - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/metadata/annotations', - value: annotations, - force: true, - }) -} - -function initScheduleBackupForEdit({ getValue, model, setDiscriminatorValue }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function initScheduleBackup({ getValue, model }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' - else return 'no' -} - -function onScheduleBackupChange({ commit, getValue, discriminator, model }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - - if (scheduleBackup === 'no') { - // delete stashAppscodeComBackupConfiguration - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - // delete annotation from kubedbComSolr annotation - deleteKubedbComSolrDbAnnotation(getValue, model, commit) - } else { - const { isBluePrint } = getBackupConfigsAndAnnotations(getValue, model) - - // create stashAppscodeComBackupConfiguration and initialize it if not exists - - const dbName = getValue(model, '/metadata/release/name') - - if ( - !valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration') && - !isBluePrint - ) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } -} - -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') - - if (scheduleBackup === 'yes') return true - else return false -} - -// invoker form -async function initBackupInvoker({ getValue, model, storeGet, commit, axios }) { - const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( - getValue, - model, - ) - - const apiGroup = getValue(model, '/metadata/resource/group') - let kind = getValue(model, '/metadata/resource/kind') - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const name = storeGet('/route/params/name') - const namespace = storeGet('/route/query/namespace') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') - let labels = {} - - const sessions = getValue(model, '/resources/coreKubestashComBackupConfiguration/spec/sessions') - sessions[0].repositories[0].name = name - sessions[0].repositories[0].directory = `/${name}` - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/spec/sessions', - value: sessions, - force: true, - }) - - const url = `clusters/${username}/${clusterName}/proxy/${group}/${version}/namespaces/${namespace}/${resource}/${name}` - - try { - const resp = await axios.get(url) - labels = resp.data.metadata.labels - kind = resp.data.kind - } catch (e) { - console.log(e) - } - - commit('wizard/model$update', { - path: '/metadata/release', - value: { - labels: labels, - name: name, - namespace: namespace, - }, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/metadata', - value: { - labels: labels, - name: name, - namespace: namespace, - }, - force: true, - }) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration/spec/target', - value: { - apiGroup: apiGroup, - kind: kind, - name: name, - namespace: namespace, - }, - force: true, - }) - - let isStashPresetEnable = false - try { - const url = `/clusters/${username}/${clusterName}/proxy/ui.k8s.appscode.com/v1alpha1/features` - const resp = await axios.get(url) - const stashFeature = resp.data.items.filter((item) => { - return item.metadata.name === 'stash-presets' - }) - if (stashFeature[0].status?.enabled) { - isStashPresetEnable = true - } - } catch (e) { - console.log(e) - } - let schedule = '' - let storageRefName = '' - let storageRefNamespace = '' - let retentionPolicyName = '' - let retentionPolicyNamespace = '' - let encryptionSecretName = '' - let encryptionSecretNamespace = '' - - if (isStashPresetEnable) { - try { - const url = `clusters/${username}/${clusterName}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/stash-presets` - const resp = await axios.get(url) - schedule = resp.data.spec.values.spec.backup.kubestash.schedule - storageRefName = resp.data.spec.values.spec.backup.kubestash.storageRef.name - storageRefNamespace = resp.data.spec.values.spec.backup.kubestash.storageRef.namespace - retentionPolicyName = resp.data.spec.values.spec.backup.kubestash.retentionPolicy.name - retentionPolicyNamespace = - resp.data.spec.values.spec.backup.kubestash.retentionPolicy.namespace - encryptionSecretName = resp.data.spec.values.spec.backup.kubestash.encryptionSecret.name - encryptionSecretNamespace = - resp.data.spec.values.spec.backup.kubestash.encryptionSecret.namespace - } catch (e) { - console.log(e) - } - } - setInitSchedule( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions/', - schedule, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'storageRef', - 'namespace', - storageRefNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'storageRef', - 'name', - storageRefName, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'retentionPolicy', - 'namespace', - retentionPolicyNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/backends', - 'retentionPolicy', - 'name', - retentionPolicyName, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions', - 'encryptionSecret', - 'namespace', - encryptionSecretNamespace, - ) - setFileValueFromStash( - { getValue, commit, model }, - 'resources/coreKubestashComBackupConfiguration/spec/sessions', - 'encryptionSecret', - 'name', - encryptionSecretName, - ) - - if (stashAppscodeComBackupConfiguration) return 'backupConfiguration' - else if (isBluePrint) return 'backupBlueprint' - else return undefined -} - -function onBackupInvokerChange({ getValue, discriminator, commit, model }) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - - if (backupInvoker === 'backupConfiguration') { - // delete annotation and create backup config object - deleteKubedbComSolrDbAnnotation(getValue, model, commit) - const dbName = getValue(model, '/metadata/release/name') - - if (!valueExists(model, getValue, '/resources/stashAppscodeComBackupConfiguration')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration', - value: stashAppscodeComBackupConfiguration, - }) - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - } - } else if (backupInvoker === 'backupBlueprint') { - // delete backup configuration object and create the annotation - commit('wizard/model$delete', '/resources/stashAppscodeComBackupConfiguration') - addKubedbComSolrDbAnnotation(getValue, model, commit, 'stash.appscode.com/backup-blueprint', '') - } -} - -function showInvokerForm({ getValue, discriminator, watchDependency }, value) { - const backupInvoker = getValue(discriminator, '/backupInvoker') - watchDependency('discriminator#/backupInvoker') - - return backupInvoker === value -} - -// backup configuration form -function initalizeTargetReferenceName({ getValue, model, watchDependency }) { - const databaseName = getValue(model, '/metadata/release/name') - watchDependency('model#/metadata/release/name') - - return databaseName -} - -// restore session repository -function setInitialRestoreSessionRepo({ getValue, model }) { - const value = getValue(model, 'resources/stashAppscodeComRepository_init_repo') - return value ? 'create' : 'select' -} - -// backup config repository -function initRepositoryChoise({ getValue, model }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - - if (stashAppscodeComRepository_repo) return 'create' - else return 'select' -} - -function initRepositoryChoiseForEdit({ getValue, model, setDiscriminatorValue }) { - const stashAppscodeComRepository_repo = getValue( - model, - '/resources/stashAppscodeComRepository_repo', - ) - const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' - setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) - - return repoInitialSelectionStatus -} - -function onRepositoryChoiseChange({ getValue, discriminator, watchDependency, commit, model }) { - const repositoryChoise = getValue(discriminator, '/repositoryChoise') - watchDependency('discriminator#/repositoryChoise') - - if (repositoryChoise === 'select') { - // delete the stashAppscodeComRepository_repo - commit('wizard/model$delete', '/resources/stashAppscodeComRepository_repo') - } else if (repositoryChoise === 'create') { - // create new stashAppscodeComRepository_repo - if (!valueExists(model, getValue, '/resources/stashAppscodeComRepository_repo')) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRepository_repo', - value: stashAppscodeComRepository_repo, - }) - const repositoryName = `${getValue(model, '/metadata/release/name')}-repo` - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) - } - } -} - -function onRepositoryNameChange({ getValue, model, commit }) { - const repositoryName = getValue(model, 'resources/stashAppscodeComRepository_repo/metadata/name') - // set this name in stashAppscodeComRestoreSession_init - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: repositoryName, - }) -} - -// backup blueprint form -function getMongoAnnotations(getValue, model) { - const annotations = getValue(model, '/resources/kubedbComSolr/metadata/annotations') - return { ...annotations } || {} -} - -function initFromAnnotationValue({ getValue, model }, key) { - const annotations = getMongoAnnotations(getValue, model) - return annotations[key] -} - -function onBackupBlueprintNameChange({ getValue, discriminator, commit, model }) { - const backupBlueprintName = getValue(discriminator, '/backupBlueprintName') - addKubedbComSolrDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/backup-blueprint', - backupBlueprintName, - true, - ) -} - -function onBackupBlueprintScheduleChange({ getValue, discriminator, commit, model }) { - const backupBlueprintSchedule = getValue(discriminator, '/schedule') - addKubedbComSolrDbAnnotation( - getValue, - model, - commit, - 'stash.appscode.com/schedule', - backupBlueprintSchedule, - true, - ) -} - -function initFromAnnotationKeyValue({ getValue, model }, prefix) { - const annotations = getMongoAnnotations(getValue, model) - const newOb = {} - Object.keys(annotations).forEach((key) => { - if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, '') - newOb[newKey] = annotations[key] - } - }) - return newOb -} - -function onTaskParametersChange({ getValue, discriminator, model, commit }) { - const taskParameters = getValue(discriminator, '/taskParameters') - - const taskParamterKeys = Object.keys(taskParameters).map( - (tp) => `params.stash.appscode.com/${tp}`, - ) - const oldAnnotations = getValue(model, '/resources/kubedbComSolr/metadata/annotations') || {} - const newAnnotations = {} - - const filteredAnnotationKeys = Object.keys(oldAnnotations).filter( - (key) => !taskParamterKeys.includes(key) && !key.startsWith('params.stash.appscode.com/'), - ) - - filteredAnnotationKeys.forEach((key) => { - newAnnotations[key] = oldAnnotations[key] - }) - - Object.keys(taskParameters).forEach((tpk) => { - newAnnotations[`params.stash.appscode.com/${tpk}`] = taskParameters[tpk] - }) - - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/metadata/annotations', - value: newAnnotations, - }) -} - -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} - -function onNamespaceChange({ commit, model, getValue }) { - const namespace = getValue(model, '/metadata/release/namespace') - const agent = getValue(model, '/resources/kubedbComSolr/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/namespaceSelector/matchNames', - value: [namespace], - force: true, - }) - } -} - -function onLabelChange({ commit, model, getValue }) { - const labels = getValue(model, '/resources/kubedbComSolr/spec/metadata/labels') - - const agent = getValue(model, '/resources/kubedbComSolr/spec/monitor/agent') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } -} - -function onNameChange({ commit, model, getValue }) { - const dbName = getValue(model, '/metadata/release/name') - - const agent = getValue(model, '/resources/kubedbComSolr/spec/monitor/agent') - - const labels = getValue(model, '/resources/kubedbComSolr/spec/metadata/labels') - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', - value: labels, - force: true, - }) - } - - const scheduleBackup = getValue(model, '/resources/stashAppscodeComBackupConfiguration') - - if (scheduleBackup) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComBackupConfiguration/spec/repository/name', - value: `${dbName}-repo`, - force: true, - }) - } - } - - const prePopulateDatabase = getValue(model, '/resources/stashAppscodeComRestoreSession_init') - - if (prePopulateDatabase) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/target/ref/name', - value: dbName, - force: true, - }) - const creatingNewRepo = getValue(model, '/resources/stashAppscodeComRepository_init_repo') - if (creatingNewRepo) { - commit('wizard/model$update', { - path: '/resources/stashAppscodeComRestoreSession_init/spec/repository/name', - value: `${dbName}-init-repo`, - force: true, - }) - } - } - - // to reset configSecret name field - const hasSecretConfig = getValue(model, '/resources/secret_user_config') - if (hasSecretConfig) { - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/configSecret/name', - value: `${dbName}-config`, - force: true, - }) - } -} - -function returnFalse() { - return false -} - -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComSolr/spec/monitor/agent') - - if (!agent) { - removeCertificatesOfAliases({ model, getValue, commit }, ['metrics-exporter']) - } - - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) - - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') - } -} - -//////////////////// service monitor /////////////////// - -function isEqualToServiceMonitorType({ rootModel, watchDependency }, value) { - watchDependency('rootModel#/spec/type') - return rootModel && rootModel.spec && rootModel.spec.type === value -} - -//////////////////// custom config ///////////////// -function onConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_user_config') - commit('wizard/model$delete', '/resources/config_secret') - } else { - const value = getValue(model, '/resources/secret_user_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_user_config', - value: {}, - force: true, - }) - } - const configSecretName = `${getValue(model, '/metadata/release/name')}-config` - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/configSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function setConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_user_config') - if (modelValue) { - return 'create-new-config' - } - return 'use-existing-config' -} - -function setConfigFiles({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/secret_user_config/stringData') - const configFiles = getValue(model, '/resources/secret_user_config/stringData') - - const files = [] - - for (const item in configFiles) { - const obj = {} - obj.key = item - obj.value = configFiles[item] - files.push(obj) - } - - setDiscriminatorValue('/configFiles', files) - - return files -} - -function onConfigFilesChange({ discriminator, getValue, commit }) { - const files = getValue(discriminator, '/configFiles') - - const configFiles = {} - - if (files) { - files.forEach((item) => { - const { key, value } = item - configFiles[key] = value - }) - } - - commit('wizard/model$update', { - path: '/resources/secret_user_config/stringData', - value: configFiles, - force: true, - }) -} - -function onSetCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/configSecret') - commit('wizard/model$delete', '/resources/secret_user_config') - } -} - -function initSetCustomConfig({ model, getValue }) { - const configSecret = getValue(model, '/resources/kubedbComSolr/spec/configSecret/name') - - if (configSecret) return 'yes' - else return 'no' -} - -//////////////////// secret custom config ///////////////// -function onSecretConfigurationSourceChange({ getValue, discriminator, commit, model }) { - const configurationSource = getValue(discriminator, '/configurationSource') - if (configurationSource === 'use-existing-config') { - commit('wizard/model$delete', '/resources/secret_secure_config') - } else { - const value = getValue(model, '/resources/secret_secure_config') - if (!value) { - commit('wizard/model$update', { - path: '/resources/secret_secure_config', - value: {}, - force: true, - }) } - const configSecretName = `${getValue(model, '/metadata/release/name')}-secure-config` - commit('wizard/model$update', { - path: '/resources/kubedbComSolr/spec/secureConfigSecret/name', - value: configSecretName, - force: true, - }) - } -} - -function setSecretConfigurationSource({ model, getValue }) { - const modelValue = getValue(model, '/resources/secret_secure_config') - if (modelValue) { - return 'create-new-config' } - return 'use-existing-config' -} - -function setSecretConfigFiles({ model, getValue, watchDependency, setDiscriminatorValue }) { - watchDependency('model#/resources/secret_secure_config/stringData') - const configFiles = getValue(model, '/resources/secret_secure_config/stringData') - - const files = [] - for (const item in configFiles) { - const obj = {} - obj.key = item - obj.value = configFiles[item] - files.push(obj) + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } - setDiscriminatorValue('/configFiles', files) - - return files -} - -function onSecretConfigFilesChange({ discriminator, getValue, commit }) { - const files = getValue(discriminator, '/configFiles') - - const configFiles = {} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - if (files) { - files.forEach((item) => { - const { key, value } = item - configFiles[key] = value + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - } - - commit('wizard/model$update', { - path: '/resources/secret_secure_config/stringData', - value: configFiles, - force: true, - }) -} - -function onSetSecretCustomConfigChange({ discriminator, getValue, commit }) { - const value = getValue(discriminator, '/setSecretCustomConfig') - - if (value === 'no') { - commit('wizard/model$delete', '/resources/kubedbComSolr/spec/secureConfigSecret') - commit('wizard/model$delete', '/resources/secret_secure_config') - } -} - -function initSetSecureCustomConfig({ model, getValue }) { - const configSecret = getValue(model, '/resources/kubedbComSolr/spec/secureConfigSecret/name') - if (configSecret) return 'yes' - else return 'no' -} - -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/solropsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` -} - -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } -} - -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function showScheduleBackup({ storeGet }) { - const operationQuery = storeGet('/route/params/actions') || '' - const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false - return !isBackupOperation -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function showBackupOptions({ discriminator, getValue, watchDependency }, backup) { - const backupEnabled = getValue(discriminator, '/backupEnabled') - if (backupEnabled) { - if (backup === 'alert') return true - else return false - } else { - if (backup === 'alert') return false - else return true + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) } -} -function isBlueprintOption({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/blueprintOptions') - const blueprintOptions = getValue(discriminator, '/blueprintOptions') - return blueprintOptions === value -} - -function ifUsagePolicy({ discriminator, getValue, watchDependency, model }, value) { - watchDependency( - 'model#/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - const usagePolicy = getValue( - model, - '/resources/coreKubestashComBackupBlueprint/spec/usagePolicy/allowedNamespaces/from/default', - ) - return usagePolicy === value -} + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( + model, + '/resources/kubedbComSolr/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -async function getBlueprints({ getValue, model, setDiscriminatorValue, axios, storeGet }, backup) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const url = `clusters/${username}/${clusterName}/proxy/core.kubestash.com/v1alpha1/backupblueprints` - - try { - const resp = await axios.get(url) - let data = resp.data.items - return data - } catch (e) { - console.log(e) - } -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + if (!configMapName) return [] -async function fetchNamespaces({ axios, storeGet }) { - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const group = storeGet('/route/params/group') - const version = storeGet('/route/params/version') - const resource = storeGet('/route/params/resource') + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) - const url = `clusters/${username}/${clusterName}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews` + const configMaps = (resp && resp.data && resp.data.data) || {} - try { - const resp = await axios.post(url, { - _recurringCall: false, - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] - } - } catch (e) { - console.log(e) - } - return [] -} -async function fetchNames( - { getValue, axios, storeGet, watchDependency, discriminator }, - version, - type, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const username = storeGet('/route/params/user') - const clusterName = storeGet('/route/params/cluster') - const namespace = getValue(discriminator, `${discriminatorName}`) - const url = - type !== 'secrets' - ? `clusters/${username}/${clusterName}/proxy/storage.kubestash.com/${version}/namespaces/${namespace}/${type}` - : `clusters/${username}/${clusterName}/proxy/core/${version}/namespaces/${namespace}/${type}` - try { - if (namespace) { - const resp = await axios.get(url) - let data = resp.data.items - data = data.map((ele) => ele.metadata.name) - return data + return configMapKeys + } catch (e) { + console.log(e) + return [] } - } catch (e) { - console.log(e) } - return [] -} - -function initBlueprint() { - return 'create' -} -function initUsagePolicy() { - return 'Same' -} - -function onInputChange( - { getValue, discriminator, commit, model }, - modelPath, - field, - subfield, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} -function setFileValueFromStash({ getValue, commit, model }, modelPath, field, subfield, value) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') backends[0][field][subfield] = value - else backends[0]['repositories'][0][field][subfield] = value - commit('wizard/model$update', { - path: modelPath, - value: backends, - }) -} - -function onInputChangeSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - discriminatorName, -) { - watchDependency(`discriminator#/${discriminatorName}`) - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} -function setInitSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - value, -) { - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} - -function getDefault({ getValue, model }, modelPath, field, subfield) { - const backends = getValue(model, modelPath) - if (field !== 'encryptionSecret') return backends[0][field][subfield] - else { - return backends[0]['repositories'][0][field][subfield] - } -} + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') -function getDefaultSchedule( - { getValue, discriminator, watchDependency, commit, model }, - modelPath, - discriminatorName, -) { - watchDependency(`model#/${modelPath}`) - const session = getValue(model, modelPath) - return session[0].scheduler.schedule -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -////////////////// auto scaler ////////////// -let autoscaleType = '' -let dbDetails = {} + const secrets = (resp && resp.data && resp.data.items) || [] -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` - commit('wizard/model$update', { - path: '/metadata/name', - value: modifiedName, - force: true, - }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: namespace, - force: true, + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} - -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} - -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/metadata/namespace') - const namespace = getValue(model, '/metadata/namespace') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/solrs`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComSolr/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) - const resources = (resp && resp.data && resp.data.items) || [] + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + if (!secretName) return [] -async function getDbDetails({ setDiscriminatorValue, commit, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') || '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { try { const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/solrs/${name}`, + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) - } - } - - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComRedisAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComRedisAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} - -async function dbTypeEqualsTo({ axios, storeGet, watchDependency, model, getValue, commit }, type) { - watchDependency('discriminator#/dbDetails') - - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) verd = 'topology' - else verd = 'standalone' - clearSpecModel({ commit }, verd) - return type === verd && spec -} - -function clearSpecModel({ commit }, dbtype) { - if (dbtype === 'node') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSolrAutoscaler/spec/${autoscaleType}/data`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSolrAutoscaler/spec/${autoscaleType}/ingest`, - ) - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSolrAutoscaler/spec/${autoscaleType}/master`, - ) - } else if (dbtype === 'topology') { - commit( - 'wizard/model$delete', - `/resources/autoscalingKubedbComSolrAutoscaler/spec/${autoscaleType}/node`, - ) - } -} - -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') || '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/metadata/name', - value: modifiedName, - force: true, - }) - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComSolrAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComSolrAutoscaler/spec/compute') -} - -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue(model, '/metadata/namespace') - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name', - ) - } -} + const secret = (resp && resp.data && resp.data.data) || {} -function ifScalingTypeEqualsTo( - { storeGet, watchDependency, getValue, discriminator, model }, - type, -) { - watchDependency('discriminator#/autoscalingType') - watchDependency('model#/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name') - - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] - } else autoscaleType = getValue(discriminator, '/autoscalingType') || '' - const isDatabaseSelected = !!getValue( - model, - '/resources/autoscalingKubedbComSolrAutoscaler/spec/databaseRef/name', - ) - return autoscaleType === type && isDatabaseSelected -} + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + return secretKeys + } catch (e) { + console.log(e) + return [] + } } - return [] -} - -function isNodeTopologySelected({ watchDependency, model, getValue }, type) { - watchDependency( - `model#/resources/autoscalingKubedbComSolrAutoscaler/spec/${type}/nodeTopology/name`, - ) - const nodeTopologyName = - getValue( - model, - `/resources/autoscalingKubedbComSolrAutoscaler/spec/${type}/nodeTopology/name`, - ) || '' - return !!nodeTopologyName.length -} - -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComSolrAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} - -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} -function setApplyToIfReady() { - return 'IfReady' -} - -function handleUnit({ commit, model, getValue }, path, type = 'bound') { - let value = getValue(model, `/resources/${path}`) - if (type === 'scalingRules') { - const updatedValue = [] - value?.forEach((ele) => { - let appliesUpto = ele['appliesUpto'] - let threshold = ele['threshold'] - if (appliesUpto && !isNaN(appliesUpto)) { - appliesUpto += 'Gi' - } - if (!isNaN(threshold)) { - threshold += 'pc' - } - updatedValue.push({ threshold, appliesUpto }) - }) - if (JSON.stringify(updatedValue) !== JSON.stringify(value)) { - commit('wizard/model$update', { - path: `/resources/${path}`, - value: updatedValue, - force: true, - }) + function addOrRemoveBinding() { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const labels = getValue(model, '/resources/kubedbComSolr/metadata/labels') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'SolrBinding', + metadata: { + labels, + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, } - } else { - if (!isNaN(value)) { - value += 'Gi' + + if (value) { commit('wizard/model$update', { - path: `/resources/${path}`, - value: value, + path: '/resources/catalogAppscodeComSolrBinding', + value: bindingValues, force: true, }) + } else { + commit('wizard/model$delete', '/resources/catalogAppscodeComSolrBinding') } } -} - -function isBindingAlreadyOn({ model, getValue }) { - const value = getValue(model, '/resources') - const keys = Object.keys(value) - isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComSolrBinding') - 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 labels = getValue(model, '/resources/kubedbComSolr/metadata/labels') - const bindingValues = { - apiVersion: 'catalog.appscode.com/v1alpha1', - kind: 'SolrBinding', - metadata: { - labels, - name: dbName, - namespace: dbNamespace, - }, - spec: { - sourceRef: { - name: dbName, - namespace: dbNamespace, - }, - }, + function isBindingAlreadyOn() { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + const isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComSolrBinding') + return isExposeBinding } - if (value) { - await commit('wizard/model$update', { - path: '/resources/catalogAppscodeComSolrBinding', - value: bindingValues, - force: true, - }) - } else { - await commit('wizard/model$delete', '/resources/catalogAppscodeComSolrBinding') + function setValueFromDbDetails(path) { + const value = getValue(model, path) + return value } -} -function setMetadata({ storeGet, mode, commit }) { - const dbname = storeGet('/route/params/name') || '' - const namespace = storeGet('/route/query/namespace') || '' - if (mode === 'standalone-step') { - commit('wizard/model$update', { - path: '/metadata/release/name', - value: dbname, - force: true, - }) - commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, - force: true, - }) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } -} - -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) - - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups - } catch (e) { - console.log(e) - return [] - } - } -} + function isTopology() { + // watchDependency('model#/resources/kubedbComSolr/spec/topology') + const topo = getValue(model, '/resources/kubedbComSolr/spec/topology') -function setAllowedMachine({ model, getValue }, type, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComSolrAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + return !!topo } - const machine = parsedInstance[type] || '' - const mx = machine?.includes(',') ? machine.split(',')[1] : '' - const mn = machine?.includes(',') ? machine.split(',')[0] : '' - - if (minmax === 'min') return mn - else return mx -} - -async function getMachines({ getValue, watchDependency, discriminator }, type, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${type}-${depends}` - - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) - - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] - - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) - - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) - - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) - - return dependantIndex === -1 ? machines : filteredMachine -} - -function hasAnnotations({ model, getValue }, type) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComSolrAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - - return !!instance -} - -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} - -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComSolrAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function isNotTopology() { + return !isTopology() } - const minMachine = getValue(discriminator, `/allowedMachine-${type}-min`) - const maxMachine = getValue(discriminator, `/allowedMachine-${type}-max`) - const minMaxMachine = `${minMachine},${maxMachine}` - - parsedInstance[type] = minMaxMachine - const instanceString = JSON.stringify(parsedInstance) - annotations['kubernetes.io/instance-type'] = instanceString - - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComSolrAutoscaler/spec/compute/${type}` - - if (minMachine && maxMachine && instance !== instanceString) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: annotations, - force: true, - }) + return { + isConsole, + isKubedb, + showOpsRequestOptions, + getNamespaces, + getDbs, + getDbDetails, + initMetadata, + onNamespaceChange, + fetchNodeTopology, + isNodeTopologySelected, + setControlledResources, + setTrigger, + setApplyToIfReady, + setMetadata, + fetchTopologyMachines, + setAllowedMachine, + getMachines, + hasAnnotations, + hasNoAnnotations, + onMachineChange, + handleUnit, + // Monitoring + isEqualToModelPathValue, + getResources, + getNamespacedResourceList, + removeCertificatesOfAliases, + showMonitoringSection, + onEnableMonitoringChange, + showCustomizeExporterSection, + onCustomizeExporterChange, + isValueExistInModel, + getOpsRequestUrl, + onNamespaceChange, + setValueFrom, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + onValueFromChange, + isEqualToValueFromType, + resourceNames, + getConfigMapKeys, + getSecrets, + getSecretKeys, + // binding + addOrRemoveBinding, + isBindingAlreadyOn, + setValueFromDbDetails, + + isRancherManaged, + isTopology, + isNotTopology, } } - -return { - setMetadata, - handleUnit, - isConsole, - getNamespaces, - getDbs, - isKubedb, - getDbDetails, - dbTypeEqualsTo, - clearSpecModel, - initMetadata, - onNamespaceChange, - ifScalingTypeEqualsTo, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - showOpsRequestOptions, - setInitSchedule, - fetchNames, - fetchNamespaces, - isRancherManaged, - onInputChangeSchedule, - getDefaultSchedule, - getBlueprints, - ifUsagePolicy, - initUsagePolicy, - isBlueprintOption, - initBlueprint, - getDefault, - onInputChange, - showBackupOptions, - showScheduleBackup, - fetchJsons, - disableLableChecker, - isEqualToModelPathValue, - getResources, - isEqualToDiscriminatorPath, - setValueFromModel, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - returnTrue, - returnStringYes, - isTopology, - isNotTopology, - isDiscriminatorEqualTo, - isAuthPluginNotSearchGuard, - showInternalUsersAndRolesMapping, - showSecureCustomConfig, - getSolrVersions, - isSecurityEnabled, - onDisableSecurityChange, - onVersionChange, - onEnableSSLChange, - removeCertificatesOfAliases, - setDatabaseMode, - getStorageClassNames, - getStorageClassNamesFromDiscriminator, - deleteDatabaseModePath, - isEqualToDatabaseMode, - getSelectedVersionAuthPlugin, - onNodeSwitchFalse, - hasTopologyNode, - hideNode, - disableNode, - setInitialStatusFalse, - onInternalUsersChange, - disableRoleDeletion, - setInternalUsers, - validateNewUser, - disableUsername, - disableUserEdit, - isAuthPluginEqualTo, - showExistingCredSection, - showPasswordCredSection, - onRolesMappingChange, - setRolesMapping, - disableRolesEdit, - disableRoleName, - validateNewRole, - disableUserDeletion, - onCustomizeKernelSettingChange, - getInternalUsers, - setApiGroup, - setApiGroupEdit, - getIssuerRefsName, - hasIssuerRefName, - hasNoIssuerRefName, - setClusterAuthMode, - setSSLMode, - showTlsConfigureSection, - onTlsConfigureChange, - showTlsRecommendation, - getAliasOptions, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - disableInitializationSection, - valueExists, - initPrePopulateDatabase, - onPrePopulateDatabaseChange, - initDataSource, - onDataSourceChange, - initVolumeType, - onVolumeTypeChange, - showInitializationForm, - showScriptOrStashForm, - showConfigMapOrSecretName, - initializeNamespace, - showRepositorySelectOrCreate, - onInitRepositoryChoiseChange, - initCustomizeRestoreJobRuntimeSettings, - initCustomizeRestoreJobRuntimeSettingsForBackup, - onCustomizeRestoreJobRuntimeSettingsChange, - onCustomizeRestoreJobRuntimeSettingsChangeForBackup, - showRuntimeForm, - getImagePullSecrets, - getBackupConfigsAndAnnotations, - deleteKubedbComSolrDbAnnotation, - addKubedbComSolrDbAnnotation, - initScheduleBackup, - initScheduleBackupForEdit, - onScheduleBackupChange, - showBackupForm, - initBackupInvoker, - onBackupInvokerChange, - showInvokerForm, - initalizeTargetReferenceName, - setInitialRestoreSessionRepo, - initRepositoryChoise, - initRepositoryChoiseForEdit, - onRepositoryChoiseChange, - onRepositoryNameChange, - getMongoAnnotations, - initFromAnnotationValue, - onBackupBlueprintNameChange, - onBackupBlueprintScheduleChange, - initFromAnnotationKeyValue, - onTaskParametersChange, - isValueExistInModel, - onNamespaceChange, - onLabelChange, - onNameChange, - returnFalse, - onAgentChange, - getCreateAuthSecret, - showExistingSecretSection, - showPasswordSection, - encodePassword, - decodePassword, - onCreateAuthSecretChange, - setAuthSecretPassword, - onAuthSecretPasswordChange, - showSecretSection, - getSecrets, - isEqualToServiceMonitorType, - onConfigurationSourceChange, - setConfigurationSource, - getMaxUnavailableOptions, - setConfigFiles, - onConfigFilesChange, - onSetCustomConfigChange, - onSecretConfigurationSourceChange, - setSecretConfigurationSource, - setSecretConfigFiles, - onSecretConfigFilesChange, - onSetSecretCustomConfigChange, - initSetCustomConfig, - initSetSecureCustomConfig, - getOpsRequestUrl, - getCreateNameSpaceUrl, - isVariantAvailable, - setStorageClass, - isBindingAlreadyOn, - addOrRemoveBinding, - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, -} diff --git a/charts/kubedbcom-zookeeper-editor-options/ui/create-ui.yaml b/charts/kubedbcom-zookeeper-editor-options/ui/create-ui.yaml index f943f17627..2fca41c582 100644 --- a/charts/kubedbcom-zookeeper-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-zookeeper-editor-options/ui/create-ui.yaml @@ -1,298 +1,284 @@ -steps: -- form: - discriminator: - bundleApiLoaded: - default: false - type: boolean - elements: - - computed: initBundle - if: returnFalse - type: label-element - - disableUnselect: true - fetch: getAdminOptions|databases/ZooKeeper/versions - if: isToggleOn|databases/ZooKeeper/versions - label: - text: labels.database.version - schema: - $ref: schema#/properties/spec/properties/admin/properties/databases/properties/ZooKeeper/properties/versions/properties/default +step: +- type: single-step-form + loader: initBundle + elements: + - disableUnselect: true + loader: getAdminOptions|databases/ZooKeeper/versions + if: + type: function + name: isToggleOn|databases/ZooKeeper/versions + label: Database Version + schema: schema/properties/spec/properties/admin/properties/databases/properties/ZooKeeper/properties/versions/properties/default + type: select + - init: + type: func + value: getDefault|databases/ZooKeeper/mode + loader: getAdminOptions|databases/ZooKeeper/mode + isHorizontal: true + if: + type: function + name: isToggleOn|databases/ZooKeeper/mode + label: Database Mode + schema: schema/properties/spec/properties/mode + type: radio + - if: + type: function + name: isEqualToModelPathValue|Replicaset|/spec/mode + label: Replicas + schema: schema/properties/spec/properties/replicas + type: input + - elements: + - init: + type: func + value: setMachineToCustom + loader: getMachineListForOptions + label: Machine + schema: schema/properties/spec/properties/podResources/properties/machine type: select - - computed: getDefault|databases/ZooKeeper/mode - fetch: getAdminOptions|databases/ZooKeeper/mode - hasDescription: true - if: isToggleOn|databases/ZooKeeper/mode - label: - text: labels.database.mode - schema: - $ref: schema#/properties/spec/properties/mode - type: radio - - if: isEqualToModelPathValue|Replicaset|/spec/mode - label: - text: labels.cluster.replicas - schema: - $ref: schema#/properties/spec/properties/replicas + - init: + type: func + value: setLimits|cpu + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: CPU + watcher: + func: setRequests|cpu + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu type: input + - init: + type: func + value: setLimits|memory + disable: isMachineNotCustom + if: + type: function + name: isMachineCustom + label: Memory + watcher: + func: setRequests|memory + paths: + - schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + schema: schema/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory + type: input + label: Machine Profile + showLabels: true + type: block-layout + - loader: getAdminOptions|storageClasses + label: Storage Class + schema: schema/properties/spec/properties/admin/properties/storageClasses/properties/default + type: select + - if: + type: function + name: showStorageSizeField + label: Storage Size + schema: schema/properties/spec/properties/persistence/properties/size + type: input + - description: Configure Credentials, Deployment Mode etc. + elements: - elements: - - computed: setMachineToCustom - fetch: getMachineListForOptions - label: - text: Machine - schema: - $ref: schema#/properties/spec/properties/podResources/properties/machine - type: select - - computed: setLimits|cpu - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.cpu - onChange: setRequests|cpu - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/cpu - type: input - - computed: setLimits|memory - disabled: isMachineNotCustom - if: isMachineCustom - label: - text: labels.memory - onChange: setRequests|memory - schema: - $ref: schema#/properties/spec/properties/podResources/properties/resources/properties/requests/properties/memory - type: input - label: - text: labels.machine_profile - show_label: true - type: single-step-form - - fetch: getAdminOptions|storageClasses - label: - text: labels.storage.class - schema: - $ref: schema#/properties/spec/properties/admin/properties/storageClasses/properties/default + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + hideBlock: true + label: Labels & Annotations + showLabels: true + type: block-layout + - init: + type: func + value: getDefault|deletionPolicy + customClass: mt-20 + if: + type: function + name: isToggleOn|deletionPolicy + label: Deletion Policy + watcher: + func: setStorageClass + paths: + - schema/properties/spec/properties/deletionPolicy + options: + - description: options.deletionPolicy.delete.description + text: Delete ( Keep only database Secrets and backed up data ) + value: Delete + - description: options.deletionPolicy.halt.description + text: Halt ( Keep PVCs, database Secrets and backed up data ) + value: Halt + - description: options.deletionPolicy.wipeOut.description + text: WipeOut ( Delete everything including backed up data ) + value: WipeOut + - description: options.deletionPolicy.doNotTerminate.description + text: DoNotTerminate ( Prevent deletion of the ZooKeeper CRD ) + value: DoNotTerminate + schema: schema/properties/spec/properties/deletionPolicy type: select - - if: showStorageSizeField - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/persistence/properties/size + - if: + type: function + name: getDefaultValue|spec/admin/authCredential/customize + label: Provide Authentication Credentials? + watcher: + func: onAuthChange + paths: + - temp/createAuthSecret + schema: temp/createAuthSecret + type: switch + - if: + type: function + name: showReferSecretSwitch + label: Refer existing Secret? + watcher: + func: onReferSecretChange + paths: + - temp/referSecret + schema: temp/referSecret + type: switch + - loader: getReferSecrets + if: + type: function + name: showSecretDropdown + label: Secret + schema: schema/properties/spec/properties/authSecret/properties/name + type: select + - if: + type: function + name: showReferSecret + label: Password (leave it blank to auto generate password) + schema: schema/properties/spec/properties/authSecret/properties/password type: input - - accordion: true - description: - text: Configure Credentials, Deployment Mode etc. - discriminator: - configDatabase: - default: false - type: boolean - createAuthSecret: - default: false - type: boolean - referSecret: - default: false - type: boolean - elements: - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.annotations.label - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - computed: getDefault|deletionPolicy - customClass: mt-20 - if: isToggleOn|deletionPolicy - label: - text: labels.deletionPolicy - onChange: setStorageClass - options: - - description: options.deletionPolicy.delete.description - text: options.deletionPolicy.delete.label - value: Delete - - description: options.deletionPolicy.halt.description - text: options.deletionPolicy.halt.label - value: Halt - - description: options.deletionPolicy.wipeOut.description - text: options.deletionPolicy.wipeOut.label - value: WipeOut - - description: options.deletionPolicy.doNotTerminate.description - text: options.deletionPolicy.doNotTerminate.label - value: DoNotTerminate - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - if: getDefaultValue|spec/admin/authCredential/customize - label: - text: Provide Authentication Credentials? - onChange: onAuthChange - schema: - $ref: discriminator#/createAuthSecret - type: switch - - if: showReferSecretSwitch - label: - text: Refer existing Secret? - onChange: onReferSecretChange - schema: - $ref: discriminator#/referSecret - type: switch - - fetch: getReferSecrets - if: showSecretDropdown - label: - text: Secret - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/name - type: select - - if: showReferSecret - label: - text: labels.password - schema: - $ref: schema#/properties/spec/properties/authSecret/properties/password - type: input - - computed: isConfigAvailable - if: getDefaultValue|spec/admin/customConfiguration - label: - text: Configure Database? - onChange: clearConfiguration - schema: - $ref: discriminator#/configDatabase + - init: + type: func + value: isConfigAvailable + if: + type: function + name: getDefaultValue|spec/admin/customConfiguration + label: Configure Database? + watcher: + func: clearConfiguration + paths: + - temp/configDatabase + schema: temp/configDatabase + type: switch + - if: + type: function + name: isConfigDatabaseOn + label: Configuration + schema: schema/properties/spec/properties/configuration + type: textarea + - if: + type: function + name: isToggleOn|deployment + label: Deployment Mode + watcher: + func: setResourceLimit + paths: + - schema/properties/spec/properties/admin/properties/deployment/properties/default + options: + - description: For exploring databases when high-performance is not required. + text: Shared + value: Shared + - description: For production applications with sophisticated workload + text: Dedicated + value: Dedicated + schema: schema/properties/spec/properties/admin/properties/deployment/properties/default + type: radio + - if: + type: function + name: isToggleOn|clusterTier + isHorizontal: true + label: Cluster Tier + options: + - text: General Purpose + value: GeneralPurpose + - text: Memory Optimized + value: MemoryOptimized + - text: CPU Optimized + value: CPUOptimized + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/default + type: radio + - disableUnselect: true + loader: getAdminOptions|clusterTier/placement + if: + type: function + name: isToggleOn|clusterTier/placement + label: Placement Policy + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + type: select + - disableUnselect: true + loader: getNodeTopology + if: + type: function + name: isToggleOn|clusterTier/nodeTopology + label: Node Topology + schema: schema/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default + type: select + hideBlock: true + label: Advanced Configuration + showLabels: true + type: block-layout + - description: Enable Backup, Monitoring, TLS etc. + elements: + - elements: + - init: + type: func + value: setMonitoring + label: Enable Monitoring + watcher: + func: updateAlertValue + paths: + - temp/monitoring + schema: temp/monitoring type: switch - - if: isConfigDatabaseOn - label: - text: Configuration - schema: - $ref: schema#/properties/spec/properties/configuration - type: editor - - hasDescription: true - if: isToggleOn|deployment - label: - text: labels.deployment.name - onChange: setResourceLimit - options: - - description: labels.deployment.shared - text: Shared - value: Shared - - description: labels.deployment.dedicated - text: Dedicated - value: Dedicated - schema: - $ref: schema#/properties/spec/properties/admin/properties/deployment/properties/default - type: radio - - if: isToggleOn|clusterTier - isHorizontal: true - label: - text: labels.clusterTier + - customClass: mt-10 + if: + type: function + name: showAlerts + label: Alert Options options: - - text: General Purpose - value: GeneralPurpose - - text: Memory Optimized - value: MemoryOptimized - - text: CPU Optimized - value: CPUOptimized - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/default - type: radio - - disableUnselect: true - fetch: getAdminOptions|clusterTier/placement - if: isToggleOn|clusterTier/placement - label: - text: labels.placement - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/placement/properties/default + - text: None + value: none + - text: Critical + value: critical + - text: Warning + value: warning + - text: Info + value: info + schema: schema/properties/form/properties/alert/properties/enabled type: select - - disableUnselect: true - fetch: getNodeTopology - if: isToggleOn|clusterTier/nodeTopology - label: - text: labels.nodeTopology - schema: - $ref: schema#/properties/spec/properties/admin/properties/clusterTier/properties/nodeTopology/properties/default - type: select - hideForm: true - label: - text: Advanced Configuration - show_label: true - type: single-step-form - - accordion: true - description: - text: Enable Backup, Monitoring, TLS etc. - elements: - - discriminator: - monitoring: - default: false - type: boolean - elements: - - computed: setMonitoring - label: - text: labels.enable_monitoring - onChange: updateAlertValue - schema: - $ref: discriminator#/monitoring - type: switch - - customClass: mt-10 - if: showAlerts - label: - text: labels.alert.options - options: - - text: None - value: none - - text: Critical - value: critical - - text: Warning - value: warning - - text: Info - value: info - schema: - $ref: schema#/properties/form/properties/alert/properties/enabled - sortable: true - type: select - if: isToggleOn|monitoring - type: single-step-form - - computed: setBackup - if: isToggleOn|backup - label: - text: Enable Backup? - onChange: onBackupSwitch - schema: - $ref: discriminator#/backup + if: + type: function + name: isToggleOn|monitoring + type: block-layout + - init: + type: func + value: setBackup + if: + type: function + name: isToggleOn|backup + label: Enable Backup? + watcher: + func: onBackupSwitch + paths: + - temp/backup + schema: temp/backup + type: switch + - elements: + - label: Expose via Gateway? + schema: schema/properties/spec/properties/admin/properties/expose/properties/default type: switch - - elements: - - label: - text: Expose via Gateway? - schema: - $ref: schema#/properties/spec/properties/admin/properties/expose/properties/default - type: switch - if: isToggleOn|expose - type: single-step-form - if: showAdditionalSettings - label: - text: Additional Options - show_label: true - type: single-step-form - type: single-step-form + if: + type: function + name: isToggleOn|expose + type: block-layout + if: + type: function + name: showAdditionalSettings + label: Additional Options + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/kubedbcom-zookeeper-editor-options/ui/functions.js b/charts/kubedbcom-zookeeper-editor-options/ui/functions.js index 520b070b66..ae7e26528b 100644 --- a/charts/kubedbcom-zookeeper-editor-options/ui/functions.js +++ b/charts/kubedbcom-zookeeper-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -315,976 +317,985 @@ const modeDetails = { }, } -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} +let placement = [] +let versions = [] +let storageClass = [] +let clusterIssuers = [] +let nodetopologiesShared = [] +let nodetopologiesDedicated = [] +let features = [] -function showAuthSecretField({ discriminator, getValue, watchDependency }) { - return !showAuthPasswordField({ - discriminator, - getValue, - watchDependency, - }) -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function showStorageSizeField({ model, getValue, watchDependency }) { - const modelPathValue = getValue(model, '/spec/mode') - watchDependency('model#/spec/mode') - const validType = ['Standalone', 'Replicaset'] - return validType.includes(modelPathValue) -} + setDiscriminatorValue('bundleApiLoaded', false) + setDiscriminatorValue('configDatabase', false) + setDiscriminatorValue('createAuthSecret', false) + setDiscriminatorValue('referSecret', false) + setDiscriminatorValue('monitoring', false) + setDiscriminatorValue('backup', false) + + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -async function getResources({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function showAuthSecretField() { + return !showAuthPasswordField() + } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + function showStorageSizeField() { + const modelPathValue = getValue(model, '/spec/mode') + // watchDependency('model#/spec/mode') + const validType = ['Standalone', 'Replicaset'] + return validType.includes(modelPathValue) + } - const resources = (resp && resp.data && resp.data.items) || [] + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) -async function getMongoDbVersions({ axios, storeGet }, group, version, resource) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resources = (resp && resp.data && resp.data.items) || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null }, - }, - }, + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, - { - params: queryParams, - }, - ) + async function getMongoDbVersions(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resources = (resp && resp.data && resp.data.items) || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null }, + }, + }, + } - // keep only non deprecated versions - const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: queryParams, + }, + ) - filteredMongoDbVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - item.text = `${name} (${specVersion})` - item.value = name - return true - }) - return filteredMongoDbVersions -} + const resources = (resp && resp.data && resp.data.items) || [] + + // keep only non deprecated versions + const filteredMongoDbVersions = resources.filter((item) => item.spec && !item.spec.deprecated) -function onCreateAuthSecretChange({ discriminator, getValue, commit }) { - const createAuthSecret = getValue(discriminator, '/createAuthSecret') - if (createAuthSecret) { - commit('wizard/model$delete', '/spec/authSecret/name') - } else if (createAuthSecret === false) { - commit('wizard/model$delete', '/spec/authSecret/password') + filteredMongoDbVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + item.text = `${name} (${specVersion})` + item.value = name + return true + }) + return filteredMongoDbVersions } -} -async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + function onCreateAuthSecretChange() { + const createAuthSecret = getValue(discriminator, '/createAuthSecret') + if (createAuthSecret) { + commit('wizard/model$delete', '/spec/authSecret/name') + } else if (createAuthSecret === false) { + commit('wizard/model$delete', '/spec/authSecret/password') + } + } + + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - const secrets = (resp && resp.data && resp.data.items) || [] + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - const filteredSecrets = secrets.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + const secrets = (resp && resp.data && resp.data.items) || [] - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) -function getMachineListForOptions({ model, getValue }) { - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - let array = [] - - if (available.length) { - array = available.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - let subText = '', - text = '' - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - text = machineData.name ? machineData.name : machineData.id - } - return { text, subText, value: machine } - } + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - } else { - array = machineList - .map((machine) => { + return filteredSecrets + } + + function getMachineListForOptions() { + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + let array = [] + + if (available.length) { + array = available.map((machine) => { if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + else { + let subText = '', + text = '' + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + text = machineData.name ? machineData.name : machineData.id + } + return { text, subText, value: machine } + } }) - .filter((val) => !!val) + } else { + array = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: machine } + const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { text, subText, value: machine } + }) + .filter((val) => !!val) + } + return array } - return array -} -function setLimits({ model, getValue, commit, watchDependency }, resource, type) { - const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' - watchDependency(`model#${path}`) - const selectedMachine = getValue(model, path) || 'custom' - const reqCommitPath = type - ? `/spec/${type}/podResources/resources/limits/${resource}` - : `/spec/podResources/resources/limits/${resource}` - const comparePath = type - ? `/spec/${type}/podResources/resources/requests/${resource}` - : `/spec/podResources/resources/requests/${resource}` - - const resourceValue = getValue(model, comparePath) - const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') - const available = getValue(model, '/spec/admin/machineProfiles/available') - - let cpu = '', - memory = '' - if (available.length && selectedMachine !== 'custom') { - const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) - if (machineData) { - cpu = machineData.limits.cpu - memory = machineData.limits.memory + function setLimits(resource, type) { + const path = type ? `/spec/${type}/podResources/machine` : '/spec/podResources/machine' + // watchDependency(`model#${path}`) + const selectedMachine = getValue(model, path) || 'custom' + const reqCommitPath = type + ? `/spec/${type}/podResources/resources/limits/${resource}` + : `/spec/podResources/resources/limits/${resource}` + const comparePath = type + ? `/spec/${type}/podResources/resources/requests/${resource}` + : `/spec/podResources/resources/requests/${resource}` + + const resourceValue = getValue(model, comparePath) + const machinesFromPreset = getValue(model, '/spec/admin/machineProfiles/machines') + const available = getValue(model, '/spec/admin/machineProfiles/available') + + let cpu = '', + memory = '' + if (available.length && selectedMachine !== 'custom') { + const machineData = machinesFromPreset.find((val) => val.id === selectedMachine) + if (machineData) { + cpu = machineData.limits.cpu + memory = machineData.limits.memory + } + } else { + if (selectedMachine === 'custom') { + cpu = resourceValue + memory = resourceValue + } else { + cpu = machines[selectedMachine].resources.limits.cpu + memory = machines[selectedMachine].resources.limits.memory + } } - } else { - if (selectedMachine === 'custom') { - cpu = resourceValue - memory = resourceValue + + if (resource === 'memory') { + commit('wizard/model$update', { + path: reqCommitPath, + value: memory, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: memory, + force: true, + }) + return memory } else { - cpu = machines[selectedMachine].resources.limits.cpu - memory = machines[selectedMachine].resources.limits.memory + commit('wizard/model$update', { + path: reqCommitPath, + value: cpu, + force: true, + }) + commit('wizard/model$update', { + path: comparePath, + value: cpu, + force: true, + }) + return cpu } } - if (resource === 'memory') { + function setRequests(resource) { + const modelPath = `/spec/podResources/resources/requests/${resource}` + const val = getValue(model, modelPath) + commitPath = `/spec/podResources/resources/limits/${resource}` commit('wizard/model$update', { - path: reqCommitPath, - value: memory, + path: commitPath, + value: val, force: true, }) + } + + function setMachineToCustom() { + const machine = getValue(model, '/spec/admin/machineProfiles/default') + return machine || 'custom' + } + + async function fetchJsons(itemCtx) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } + } + + function updateAgentValue(val) { commit('wizard/model$update', { - path: comparePath, - value: memory, - force: true, - }) - return memory - } else { - commit('wizard/model$update', { - path: reqCommitPath, - value: cpu, + path: '/spec/monitoring/agent', + value: val ? 'prometheus.io/operator' : '', force: true, }) + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: comparePath, - value: cpu, + path: '/form/alert/enabled', + value: val ? 'warning' : 'none', force: true, }) - return cpu } -} - -function setRequests({ getValue, model, commit }, resource) { - const modelPath = `/spec/podResources/resources/requests/${resource}` - const val = getValue(model, modelPath) - commitPath = `/spec/podResources/resources/limits/${resource}` - commit('wizard/model$update', { - path: commitPath, - value: val, - force: true, - }) -} -function setMachineToCustom({ getValue, model }) { - const machine = getValue(model, '/spec/admin/machineProfiles/default') - return machine || 'custom' -} - -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + const ifCapiProviderIsNotEmpty = () => { + // watchDependency('model#/form/capi/provider') + const val = getValue(model, '/form/capi/provider') + if (val) return true } -} -function updateAgentValue({ commit }, val) { - commit('wizard/model$update', { - path: '/spec/monitoring/agent', - value: val ? 'prometheus.io/operator' : '', - force: true, - }) - - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: val ? 'warning' : 'none', - force: true, - }) -} + const showMultiselectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + if (val === 'capz' && ifDedicated()) return true + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + const showSelectZone = () => { + // watchDependency('model#/form/capi/dedicated') + const val = getValue(model, '/form/capi/provider') + if (val !== 'capz' && ifDedicated()) return true } -} -const ifCapiProviderIsNotEmpty = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/provider') - const val = getValue(model, '/form/capi/provider') - if (val) return true -} + const ifDedicated = () => { + const val = getValue(model, 'form/capi/dedicated') + if (val) return true + } -const showMultiselectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') + const dedicatedOnChange = () => { + const val = getValue(model, 'form/capi/dedicated') + if (!val) { + commit('wizard/model$delete', 'form/capi/zones') + commit('wizard/model$delete', 'form/capi/sku') + } + } - if (val === 'capz' && ifDedicated({ model, getValue })) return true -} + const ifZones = () => { + // watchDependency('model#/form/capi/zones') + // watchDependency('model#/form/capi/dedicated') + const zones = getValue(model, 'form/capi/zones') || [] + const isDedicated = getValue(model, 'form/capi/dedicated') + if (zones.length && isDedicated) return true + } -const showSelectZone = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/dedicated') - const val = getValue(model, '/form/capi/provider') - if (val !== 'capz' && ifDedicated({ model, getValue })) return true -} + const zonesOnChange = () => { + const zones = getValue(model, 'form/capi/zones') || [] + if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') + } -const ifDedicated = ({ model, getValue }) => { - const val = getValue(model, 'form/capi/dedicated') - if (val) return true -} + async function getZones() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const isDedicated = getValue(model, 'form/capi/dedicated') + if (isDedicated) { + try { + const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) + const val = resp.data.map((item) => { + return { value: item, text: item } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } + + async function getSKU() { + // watchDependency('model#/form/capi/zones') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const zones = getValue(model, 'form/capi/zones') || [] + if (zones.length) { + try { + let url = `clustersv2/${owner}/${cluster}/vms?` + if (typeof zones === 'string') { + url += `zones=${encodeURIComponent(zones)}` + } else { + zones.forEach((item) => { + url += `zones=${encodeURIComponent(item)}&` + }) + url = url.slice(0, -1) + } + const resp = await axios.get(url) + const val = resp.data.map((item) => { + return { + value: item.name, + text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, + } + }) + return val + } catch (e) { + console.log(e) + return [] + } + } + } -const dedicatedOnChange = ({ model, getValue, commit }) => { - const val = getValue(model, 'form/capi/dedicated') - if (!val) { - commit('wizard/model$delete', 'form/capi/zones') - commit('wizard/model$delete', 'form/capi/sku') + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false } -} -const ifZones = ({ model, getValue, watchDependency }) => { - watchDependency('model#/form/capi/zones') - watchDependency('model#/form/capi/dedicated') - const zones = getValue(model, 'form/capi/zones') || [] - const isDedicated = getValue(model, 'form/capi/dedicated') - if (zones.length && isDedicated) return true -} + function setStorageClass() { + const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' + let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' + const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] + const suffix = '-retain' -const zonesOnChange = ({ model, getValue, commit }) => { - const zones = getValue(model, 'form/capi/zones') || [] - if (!zones.length) commit('wizard/model$delete', 'form/capi/sku') -} + const simpleClassList = storageClassList.filter((item) => { + return !item.endsWith(suffix) + }) + const retainClassList = storageClassList.filter((item) => { + return item.endsWith(suffix) + }) + if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { + storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] + } else { + storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + } -async function getZones({ storeGet, axios, model, getValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const isDedicated = getValue(model, 'form/capi/dedicated') - if (isDedicated) { - try { - const resp = await axios.get(`clustersv2/${owner}/${cluster}/zones`) - const val = resp.data.map((item) => { - return { value: item, text: item } + const isChangeable = isToggleOn('storageClasses') + if (isChangeable && storageClass) { + commit('wizard/model$update', { + path: '/spec/admin/storageClasses/default', + value: storageClass, + force: true, }) - return val - } catch (e) { - console.log(e) - return [] } } -} -async function getSKU({ storeGet, axios, model, getValue, watchDependency }) { - watchDependency('model#/form/capi/zones') - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const zones = getValue(model, 'form/capi/zones') || [] - if (zones.length) { + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params try { - let url = `clustersv2/${owner}/${cluster}/vms?` - if (typeof zones === 'string') { - url += `zones=${encodeURIComponent(zones)}` + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace } else { - zones.forEach((item) => { - url += `zones=${encodeURIComponent(item)}&` - }) - url = url.slice(0, -1) + return resp.data?.status?.namespaces || [] } - const resp = await axios.get(url) - const val = resp.data.map((item) => { - return { - value: item.name, - text: `${item.name} [CPU: ${item.cpu}] [Memory: ${item.memory}mb] `, - } - }) - return val } catch (e) { console.log(e) - return [] } + return [] } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} - -function setStorageClass({ model, getValue, commit, watchDependency, discriminator }) { - const deletionPolicy = getValue(model, '/spec/deletionPolicy') || '' - let storageClass = getValue(model, '/spec/admin/storageClasses/default') || '' - const storageClassList = getValue(model, '/spec/admin/storageClasses/available') || [] - const suffix = '-retain' - - const simpleClassList = storageClassList.filter((item) => { - return !item.endsWith(suffix) - }) - const retainClassList = storageClassList.filter((item) => { - return item.endsWith(suffix) - }) - if (deletionPolicy === 'WipeOut' || deletionPolicy === 'Delete') { - storageClass = simpleClassList.length ? simpleClassList[0] : retainClassList[0] - } else { - storageClass = retainClassList.length ? retainClassList[0] : simpleClassList[0] + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - const isChangeable = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'storageClasses', - ) - if (isChangeable && storageClass) { + async function initBundle() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + + let db = getValue(model, '/metadata/resource/kind') + db = db.toLowerCase() + let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` + const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` + + try { + const resp = await axios.get(url) + features = resp.data.features || [] + placement = resp.data.placementpolicies || [] + versions = resp.data.versions || [] + storageClass = resp.data.storageclasses || [] + clusterIssuers = resp.data.clusterissuers || [] + nodetopologiesDedicated = resp.data.dedicated || [] + nodetopologiesShared = resp.data.shared || [] + + const response = await axios.get(annotationUrl) + const annotations = response.data?.metadata?.annotations || {} + const uidRange = annotations['openshift.io/sa.scc.uid-range'] + if (uidRange) { + const val = uidRange.split('/')[0] + commit('wizard/model$update', { + path: '/spec/openshift/securityContext/runAsUser', + value: val, + force: true, + }) + } + } catch (e) { + console.log(e) + } + commit('wizard/model$update', { - path: '/spec/admin/storageClasses/default', - value: storageClass, + path: '/spec/deletionPolicy', + value: getDefault('deletionPolicy'), force: true, }) - } -} -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + if (!getValue(model, `/spec/admin/databases/ZooKeeper/mode/toggle`)) { + let defMode = getDefault('databases/ZooKeeper/mode') || '' + if (defMode === '') { + const arr = getValue(model, '/spec/databases/ZooKeeper/mode/available') || [] + if (arr.length) defMode = arr[0] + } + commit('wizard/model$update', { + path: '/spec/mode', + value: defMode, + force: true, + }) } - } catch (e) { - console.log(e) - } - return [] -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} -let placement = [] -let versions = [] -let storageClass = [] -let clusterIssuers = [] -let nodetopologiesShared = [] -let nodetopologiesDedicated = [] -let features = [] -async function initBundle({ commit, model, getValue, axios, storeGet, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/release/namespace') - - let db = getValue(model, '/metadata/resource/kind') - db = db.toLowerCase() - let url = `clusters/${owner}/${cluster}/db-bundle?type=features,common,versions&db-singular=${db}` - const annotationUrl = `clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}` - - try { - const resp = await axios.get(url) - features = resp.data.features || [] - placement = resp.data.placementpolicies || [] - versions = resp.data.versions || [] - storageClass = resp.data.storageclasses || [] - clusterIssuers = resp.data.clusterissuers || [] - nodetopologiesDedicated = resp.data.dedicated || [] - nodetopologiesShared = resp.data.shared || [] - - const response = await axios.get(annotationUrl) - const annotations = response.data?.metadata?.annotations || {} - const uidRange = annotations['openshift.io/sa.scc.uid-range'] - if (uidRange) { - const val = uidRange.split('/')[0] + if (!features.includes('tls')) { commit('wizard/model$update', { - path: '/spec/openshift/securityContext/runAsUser', - value: val, + path: '/spec/admin/tls/default', + value: false, force: true, }) } - } catch (e) { - console.log(e) - } - - commit('wizard/model$update', { - path: '/spec/deletionPolicy', - value: getDefault({ getValue, model }, 'deletionPolicy'), - force: true, - }) - - if (!getValue(model, `/spec/admin/databases/ZooKeeper/mode/toggle`)) { - let defMode = getDefault({ getValue, model }, 'databases/ZooKeeper/mode') || '' - if (defMode === '') { - const arr = getValue(model, '/spec/databases/ZooKeeper/mode/available') || [] - if (arr.length) defMode = arr[0] + if (!features.includes('binding')) { + commit('wizard/model$update', { + path: '/spec/admin/expose/default', + value: false, + force: true, + }) + } + if (!features.includes('monitoring')) { + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: 'none', + force: true, + }) + } + if (!features.includes('backup')) { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: '', + force: true, + }) } - commit('wizard/model$update', { - path: '/spec/mode', - value: defMode, - force: true, - }) - } - if (!features.includes('tls')) { - commit('wizard/model$update', { - path: '/spec/admin/tls/default', - value: false, - force: true, - }) - } - if (!features.includes('binding')) { - commit('wizard/model$update', { - path: '/spec/admin/expose/default', - value: false, - force: true, - }) - } - if (!features.includes('monitoring')) { - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: 'none', - force: true, - }) - } - if (!features.includes('backup')) { - commit('wizard/model$update', { - path: '/spec/admin/archiver/enable/default', - value: false, - force: true, - }) - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: '', - force: true, - }) + setDiscriminatorValue('/bundleApiLoaded', true) } - setDiscriminatorValue('/bundleApiLoaded', true) -} + function fetchOptions(type) { + let kind = getValue(model, '/metadata/resource/kind') + + let returnArray = [] + if (type === 'clusterTier/placement') { + returnArray = placement + } else if (type === `databases/${kind}/versions`) { + returnArray = versions + } else if (type === 'storageClasses') { + returnArray = storageClass + } else if (type === 'clusterIssuers') { + returnArray = clusterIssuers + } -function fetchOptions({ model, getValue, commit }, type) { - let kind = getValue(model, '/metadata/resource/kind') - - let returnArray = [] - if (type === 'clusterTier/placement') { - returnArray = placement - } else if (type === `databases/${kind}/versions`) { - returnArray = versions - } else if (type === 'storageClasses') { - returnArray = storageClass - } else if (type === 'clusterIssuers') { - returnArray = clusterIssuers - } + if (returnArray.length === 1) { + const path = `/spec/admin/${type}/default` + commit('wizard/model$update', { + path: path, + value: returnArray[0], + force: true, + }) + } - if (returnArray.length === 1) { - const path = `/spec/admin/${type}/default` - commit('wizard/model$update', { - path: path, - value: returnArray[0], - force: true, - }) + return returnArray } - return returnArray -} - -function getAdminOptions({ getValue, model, watchDependency, commit }, type) { - watchDependency('discriminator#/bundleApiLoaded') + function getAdminOptions(type) { + // watchDependency('discriminator#/bundleApiLoaded') - const options = getValue(model, `/spec/admin/${type}/available`) || [] + const options = getValue(model, `/spec/admin/${type}/available`) || [] - if (options.length === 0) { - return fetchOptions({ model, getValue, commit }, type) - } - if (type.endsWith('/mode')) { - return ( - options?.map((item) => ({ - description: modeDetails[item]?.description || '', - text: modeDetails[item]?.text || '', - value: item, - })) || [] - ) + if (options.length === 0) { + return fetchOptions(type) + } + if (type.endsWith('/mode')) { + return ( + options?.map((item) => ({ + description: modeDetails[item]?.description || '', + text: modeDetails[item]?.text || '', + value: item, + })) || [] + ) + } + return options } - return options -} -function checkIfFeatureOn({ getValue, model }, type) { - let val = getValue(model, `/spec/admin/${type}/toggle`) - if (type === 'backup' || type === 'archiver') { - val = getValue(model, `/spec/admin/${type}/enable/toggle`) - } - const backupVal = getValue(model, '/spec/backup/tool') - - if (type === 'backup') { - return features.includes('backup') && backupVal === 'KubeStash' && val - } else if (type === 'tls') { - return features.includes('tls') && val - } else if (type === 'expose') { - return features.includes('binding') && val - } else if (type === 'monitoring') { - return features.includes('monitoring') && val - } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + function checkIfFeatureOn(type) { + let val = getValue(model, `/spec/admin/${type}/toggle`) + if (type === 'backup' || type === 'archiver') { + val = getValue(model, `/spec/admin/${type}/enable/toggle`) + } + const backupVal = getValue(model, '/spec/backup/tool') + + if (type === 'backup') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } else if (type === 'tls') { + return features.includes('tls') && val + } else if (type === 'expose') { + return features.includes('binding') && val + } else if (type === 'monitoring') { + return features.includes('monitoring') && val + } else if (type === 'archiver') { + return features.includes('backup') && backupVal === 'KubeStash' && val + } } -} -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { - watchDependency('discriminator#/bundleApiLoaded') - watchDependency('model#/spec/admin/deployment/default') - const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') - let deploymentType = getValue(model, `/spec/admin/deployment/default`) - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { - return checkIfFeatureOn({ getValue, model }, type) - } else if ( - type === 'clusterTier' || - type === 'clusterTier/placement' || - type === 'clusterTier/nodeTopology' - ) { - if (deploymentType === 'Dedicated' && bundleApiLoaded) return true - else return false - } else if (type === 'deployment') { - const deploymentType = getValue(model, '/spec/admin/deployment/default') - if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { - commit('wizard/model$update', { - path: '/spec/admin/deployment/default', - value: 'Shared', - force: true, - }) - } - return ( - getValue(model, `/spec/admin/${type}/toggle`) && - nodetopologiesDedicated.length && - bundleApiLoaded - ) - } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded -} + function isToggleOn(type) { + // watchDependency('discriminator#/bundleApiLoaded') + // watchDependency('model#/spec/admin/deployment/default') + const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') + let deploymentType = getValue(model, `/spec/admin/deployment/default`) + if ( + type === 'tls' || + type === 'backup' || + type === 'expose' || + type === 'monitoring' || + type === 'archiver' + ) { + return checkIfFeatureOn(type) + } else if ( + type === 'clusterTier' || + type === 'clusterTier/placement' || + type === 'clusterTier/nodeTopology' + ) { + if (deploymentType === 'Dedicated' && bundleApiLoaded) return true + else return false + } else if (type === 'deployment') { + const deploymentType = getValue(model, '/spec/admin/deployment/default') + if (!nodetopologiesDedicated.length && deploymentType === 'Dedicated') { + commit('wizard/model$update', { + path: '/spec/admin/deployment/default', + value: 'Shared', + force: true, + }) + } + return ( + getValue(model, `/spec/admin/${type}/toggle`) && + nodetopologiesDedicated.length && + bundleApiLoaded + ) + } else return getValue(model, `/spec/admin/${type}/toggle`) && bundleApiLoaded + } -async function getNodeTopology({ model, getValue, axios, storeGet, watchDependency }) { - watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/admin/clusterTier/default') - const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' - const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' - let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] + async function getNodeTopology() { + // watchDependency('model#/spec/admin/deployment/default') + // watchDependency('model#/spec/admin/clusterTier/default') + const deploymentType = getValue(model, '/spec/admin/deployment/default') || '' + const clusterTier = getValue(model, '/spec/admin/clusterTier/default') || '' + let nodeTopologyList = getValue(model, `/spec/admin/clusterTier/nodeTopology/available`) || [] - const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' + const provider = storeGet('/cluster/clusterDefinition/result/provider') || '' - if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared - else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated + if (deploymentType === 'Shared') nodeTopologyList = nodetopologiesShared + else if (deploymentType === 'Dedicated') nodeTopologyList = nodetopologiesDedicated - const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) - return filteredList -} + const filteredList = filterNodeTopology(nodeTopologyList, clusterTier, provider) + return filteredList + } -function filterNodeTopology(list, tier, provider) { - // first filter the list from value that exists from the filtered list got from API - const filteredlist = list + function filterNodeTopology(list, tier, provider) { + // first filter the list from value that exists from the filtered list got from API + const filteredlist = list - // filter the list based on clusterTier - if (provider === 'EKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('c') - else if (tier === 'MemoryOptimized') return item.startsWith('r') - else return !item.startsWith('c') && !item.startsWith('r') - }) - } else if (provider === 'AKS') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('e') || - item.startsWith('eb') || - item.startsWith('ec') || - item.startsWith('m') || - item.startsWith('d') - ) - else - return ( - !(item.startsWith('f') || item.startsWith('fx')) && - !( + // filter the list based on clusterTier + if (provider === 'EKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('c') + else if (tier === 'MemoryOptimized') return item.startsWith('r') + else return !item.startsWith('c') && !item.startsWith('r') + }) + } else if (provider === 'AKS') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') return item.startsWith('f') || item.startsWith('fx') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('e') || item.startsWith('eb') || item.startsWith('ec') || item.startsWith('m') || item.startsWith('d') ) - ) - }) - } else if (provider === 'GKE') { - return filteredlist.filter((item) => { - if (tier === 'CPUOptimized') - return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') - else if (tier === 'MemoryOptimized') - return ( - item.startsWith('x4') || - item.startsWith('m1') || - item.startsWith('m2') || - item.startsWith('m3') - ) - else - return ( - !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && - !( + else + return ( + !(item.startsWith('f') || item.startsWith('fx')) && + !( + item.startsWith('e') || + item.startsWith('eb') || + item.startsWith('ec') || + item.startsWith('m') || + item.startsWith('d') + ) + ) + }) + } else if (provider === 'GKE') { + return filteredlist.filter((item) => { + if (tier === 'CPUOptimized') + return item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d') + else if (tier === 'MemoryOptimized') + return ( item.startsWith('x4') || item.startsWith('m1') || item.startsWith('m2') || item.startsWith('m3') ) - ) - }) - } else return filteredlist -} + else + return ( + !(item.startsWith('h3') || item.startsWith('c2') || item.startsWith('c2d')) && + !( + item.startsWith('x4') || + item.startsWith('m1') || + item.startsWith('m2') || + item.startsWith('m3') + ) + ) + }) + } else return filteredlist + } -function returnFalse() { - return false -} + function returnFalse() { + return false + } -function isMachineCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue === 'custom' -} + function isMachineCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue === 'custom' + } -function isMachineNotCustom({ model, getValue, watchDependency }, path) { - const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' - const modelPathValue = getValue(model, fullpath) - watchDependency(`model#${fullpath}`) - return modelPathValue !== 'custom' && !!modelPathValue -} + function isMachineNotCustom(path) { + const fullpath = path ? `/spec/${path}/podResources/machine` : '/spec/podResources/machine' + const modelPathValue = getValue(model, fullpath) + // watchDependency(`model#${fullpath}`) + return modelPathValue !== 'custom' && !!modelPathValue + } -function onAuthChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) - commit('wizard/model$update', { - path: '/spec/authSecret/password', - value: '', - force: true, - }) -} + function onAuthChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/authSecret/password', + value: '', + force: true, + }) + } -function clearConfiguration({ discriminator, getValue, commit }) { - const configOn = getValue(discriminator, '/configDatabase') + function clearConfiguration() { + const configOn = getValue(discriminator, '/configDatabase') - if (!configOn) { - commit('wizard/model$delete', '/spec/configuration') + if (!configOn) { + commit('wizard/model$delete', '/spec/configuration') + } } -} -function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/configDatabase') - return getValue(discriminator, '/configDatabase') -} + function isConfigDatabaseOn() { + // watchDependency('discriminator#/configDatabase') + return getValue(discriminator, '/configDatabase') + } -function showIssuer({ model, getValue, watchDependency, discriminator }) { - watchDependency('model#/spec/admin/tls/default') - const isTlsEnabled = getValue(model, '/spec/admin/tls/default') - const isIssuerToggleEnabled = isToggleOn( - { getValue, model, watchDependency, discriminator }, - 'clusterIssuers', - ) - return isTlsEnabled && isIssuerToggleEnabled -} + function showIssuer() { + // watchDependency('model#/spec/admin/tls/default') + const isTlsEnabled = getValue(model, '/spec/admin/tls/default') + const isIssuerToggleEnabled = isToggleOn('clusterIssuers') + return isTlsEnabled && isIssuerToggleEnabled + } -function setMonitoring({ getValue, model }) { - const agent = getValue(model, '/spec/admin/monitoring/agent') || '' - return !!agent -} + function setMonitoring() { + const agent = getValue(model, '/spec/admin/monitoring/agent') || '' + return !!agent + } -function updateAlertValue({ commit, model, discriminator, getValue }) { - const isMonitorEnabled = getValue(discriminator, '/monitoring') - const alert = isMonitorEnabled ? 'warning' : 'none' - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: alert, - force: true, - }) - const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' - commit('wizard/model$update', { - path: '/spec/admin/monitoring/agent', - value: agent, - force: true, - }) -} + function updateAlertValue() { + const isMonitorEnabled = getValue(discriminator, '/monitoring') + const alert = isMonitorEnabled ? 'warning' : 'none' + // update alert value depend on monitoring profile + commit('wizard/model$update', { + path: '/form/alert/enabled', + value: alert, + force: true, + }) + const agent = isMonitorEnabled ? 'prometheus.io/operator' : '' + commit('wizard/model$update', { + path: '/spec/admin/monitoring/agent', + value: agent, + force: true, + }) + } -function showAlerts({ watchDependency, model, getValue, discriminator }) { - watchDependency('discriminator#/monitoring') - const isMonitorEnabled = getValue(discriminator, '/monitoring') - return ( - isMonitorEnabled && isToggleOn({ getValue, model, watchDependency, discriminator }, 'alert') - ) -} + function showAlerts() { + // watchDependency('discriminator#/monitoring') + const isMonitorEnabled = getValue(discriminator, '/monitoring') + return isMonitorEnabled && isToggleOn('alert') + } -function setBackup({ model, getValue }) { - const backup = getValue(model, '/spec/backup/tool') - const val = getValue(model, '/spec/admin/backup/enable/default') - return backup === 'KubeStash' && features.includes('backup') && val -} + function setBackup() { + const backup = getValue(model, '/spec/backup/tool') + const val = getValue(model, '/spec/admin/backup/enable/default') + return backup === 'KubeStash' && features.includes('backup') && val + } -function onBackupSwitch({ discriminator, getValue, commit }) { - const isBackupOn = getValue(discriminator, '/backup') - commit('wizard/model$update', { - path: '/spec/backup/tool', - value: isBackupOn ? 'KubeStash' : '', - force: true, - }) -} + function onBackupSwitch() { + const isBackupOn = getValue(discriminator, '/backup') + commit('wizard/model$update', { + path: '/spec/backup/tool', + value: isBackupOn ? 'KubeStash' : '', + force: true, + }) + } -function showAdditionalSettings({ watchDependency }) { - watchDependency('discriminator#/bundleApiLoaded') - return features.length -} + function showAdditionalSettings() { + // watchDependency('discriminator#/bundleApiLoaded') + return features.length + } -function getDefault({ getValue, model }, type) { - const val = getValue(model, `/spec/admin/${type}/default`) || '' - return val -} + function getDefault(type) { + const val = getValue(model, `/spec/admin/${type}/default`) || '' + return val + } -function isConfigAvailable({ getValue, model }) { - const val = getValue(model, '/spec/configuration') - return val !== '' -} + function isConfigAvailable() { + const val = getValue(model, '/spec/configuration') + return val !== '' + } -async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) { - const referSecret = getValue(discriminator, '/referSecret') - if (!referSecret) { - return [] + async function getReferSecrets() { + const referSecret = getValue(discriminator, '/referSecret') + if (!referSecret) { + return [] + } + + const params = storeGet('/route/params') + const { user, cluster } = params + const namespace = getValue(model, `/metadata/release/namespace`) + let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` + + const options = [] + try { + const resp = await axios.get(url) + const items = resp.data?.items + items.forEach((ele) => { + options.push(ele.metadata?.name) + }) + } catch (e) { + console.log(e) + } + return options } - const params = storeGet('/route/params') - const { user, cluster } = params - const namespace = getValue(model, `/metadata/release/namespace`) - let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets` - - const options = [] - try { - const resp = await axios.get(url) - const items = resp.data?.items - items.forEach((ele) => { - options.push(ele.metadata?.name) - }) - } catch (e) { - console.log(e) + function showAuthPasswordField() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !modelPathValue && showReferSecret() } - return options -} -function showAuthPasswordField({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showSecretDropdown() { + const modelPathValue = getValue(discriminator, '/referSecret') + // watchDependency('discriminator#/referSecret') + return !!modelPathValue && showReferSecret() + } -function showSecretDropdown({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/referSecret') - watchDependency('discriminator#/referSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function showReferSecret() { + const modelPathValue = getValue(discriminator, '/createAuthSecret') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue + } -function showReferSecret({ discriminator, getValue, watchDependency }) { - const modelPathValue = getValue(discriminator, '/createAuthSecret') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue -} + function getDefaultValue(path) { + const val = getValue(model, `/${path}`) || '' + return val + } -function getDefaultValue({ getValue, model }, path) { - const val = getValue(model, `/${path}`) || '' - return val -} + function showReferSecretSwitch() { + const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') + // watchDependency('discriminator#/createAuthSecret') + return !!modelPathValue && showReferSecret() + } -function showReferSecretSwitch({ model, getValue, watchDependency, discriminator }) { - const modelPathValue = getValue(model, '/spec/admin/authCredential/referExisting') - watchDependency('discriminator#/createAuthSecret') - return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency }) -} + function onReferSecretChange() { + commit('wizard/model$update', { + path: '/spec/authSecret/name', + value: '', + force: true, + }) + } -function onReferSecretChange({ commit }) { - commit('wizard/model$update', { - path: '/spec/authSecret/name', - value: '', - force: true, - }) -} + function setResourceLimit() { + // This function is referenced in the watcher but needs to be defined + // Add your implementation here if needed + } -return { - showReferSecretSwitch, - onReferSecretChange, - getDefaultValue, - isRancherManaged, - showSecretDropdown, - showReferSecret, - getReferSecrets, - isConfigAvailable, - initBundle, - returnFalse, - isVariantAvailable, - fetchJsons, - showAuthPasswordField, - isEqualToModelPathValue, - showAuthSecretField, - showStorageSizeField, - getResources, - getMongoDbVersions, - onCreateAuthSecretChange, - getSecrets, - getMachineListForOptions, - setLimits, - setRequests, - setMachineToCustom, - updateAgentValue, - getCreateNameSpaceUrl, - ifCapiProviderIsNotEmpty, - ifDedicated, - dedicatedOnChange, - ifZones, - zonesOnChange, - getZones, - getSKU, - showMultiselectZone, - showSelectZone, - setStorageClass, - getNamespaces, - isToggleOn, - getAdminOptions, - getNodeTopology, - filterNodeTopology, - isMachineNotCustom, - isMachineCustom, - onAuthChange, - clearConfiguration, - isConfigDatabaseOn, - showIssuer, - setMonitoring, - updateAlertValue, - showAlerts, - onBackupSwitch, - setBackup, - showAdditionalSettings, - getDefault, + return { + showReferSecretSwitch, + onReferSecretChange, + getDefaultValue, + isRancherManaged, + showSecretDropdown, + showReferSecret, + getReferSecrets, + isConfigAvailable, + initBundle, + returnFalse, + isVariantAvailable, + fetchJsons, + showAuthPasswordField, + isEqualToModelPathValue, + showAuthSecretField, + showStorageSizeField, + getResources, + getMongoDbVersions, + onCreateAuthSecretChange, + getSecrets, + getMachineListForOptions, + setLimits, + setRequests, + setMachineToCustom, + updateAgentValue, + getCreateNameSpaceUrl, + ifCapiProviderIsNotEmpty, + ifDedicated, + dedicatedOnChange, + ifZones, + zonesOnChange, + getZones, + getSKU, + showMultiselectZone, + showSelectZone, + setStorageClass, + getNamespaces, + isToggleOn, + getAdminOptions, + getNodeTopology, + filterNodeTopology, + isMachineNotCustom, + isMachineCustom, + onAuthChange, + clearConfiguration, + isConfigDatabaseOn, + showIssuer, + setMonitoring, + updateAlertValue, + showAlerts, + onBackupSwitch, + setBackup, + showAdditionalSettings, + getDefault, + setResourceLimit, + } } diff --git a/charts/kubedbcom-zookeeper-editor/ui/edit-ui.yaml b/charts/kubedbcom-zookeeper-editor/ui/edit-ui.yaml index 0fe77246d4..ef75d896b3 100644 --- a/charts/kubedbcom-zookeeper-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-zookeeper-editor/ui/edit-ui.yaml @@ -1,577 +1,595 @@ -steps: -- form: - elements: - - disabled: true - label: - text: labels.database.name - onChange: onNameChange - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - type: single-step-form - id: basic - title: steps.0.label -- form: - discriminator: - scheduleBackup: - default: "yes" - type: string - elements: - - discriminator: - backupType: - type: string - isBackupDataLoaded: - default: false - type: boolean - elements: - - computed: initBackupData - if: returnFalse - type: input - - computed: setBackupType - fetch: getTypes - hasDescription: true - if: isBackupDataLoadedTrue - label: - text: Select Backup Type - onChange: onBackupTypeChange - schema: - $ref: discriminator#/backupType - type: radio - - discriminator: - backupConfigContext: - type: string - config: - type: string - paused: - default: false - type: boolean - schedule: - type: string - elements: - - fetch: getContext - label: - text: Select Context - onChange: onContextChange - required: true - schema: - $ref: discriminator#/backupConfigContext - type: select - - fetch: getConfigList - if: showConfigList - label: - text: Select BackupConfig - onChange: onConfigChange - required: true - schema: - $ref: discriminator#/config - type: select - - computed: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions - if: showSchedule - label: - text: Schedule - onChange: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule - required: true - schema: - $ref: discriminator#/schedule - type: input - - if: showPause - label: - text: Paused - schema: - $ref: schema#/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused - type: switch - if: isBackupType|BackupConfig - type: single-step-form - - discriminator: - blueprintEnabled: - default: false - type: boolean - elements: - - computed: setBlueprintSwitch - label: - text: Enable Backup Blueprint - onChange: onBlueprintChange - schema: - $ref: discriminator#/blueprintEnabled - type: switch - if: isBackupType|BackupBlueprint - type: single-step-form - - discriminator: - archiverEnabled: - default: false - type: boolean - elements: - - computed: setArchiverSwitch - label: - text: Enable Archiver - onChange: onArchiverChange - schema: - $ref: discriminator#/archiverEnabled - type: switch - if: isBackupType|Archiver - type: single-step-form - label: - text: Backup Form - type: single-step-form - type: single-step-form - id: backupconfiguration - title: steps.4.label -- form: - discriminator: - dbDetails: - default: false - type: boolean +type: multi-step-form +step: + - type: single-step-form + id: backupconfiguration + # label: Backup + schema: schema/ elements: - - computed: getDbDetails - if: returnFalse - type: input - - elements: - - label: - text: Name - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/metadata/properties/name - type: input - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: SelectNamespace - onChange: onNamespaceChange - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/metadata/properties/namespace - type: select - - fetch: getDbs - label: - text: Select Db - onChange: initMetadata - refresh: true - required: true - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/databaseRef/properties/name - type: select - if: isConsole - type: single-step-form - - hasDescription: true - if: isConsole - label: - text: Select Type - onChange: initMetadata + - type: radio + label: Schedule a Backup? + schema: temp/properties/scheduleBackup + isHorizontal: true options: - - description: Scale your CPU Memory based on resource usage - text: Compute - value: compute - - description: Expand your database size based on volume usage - text: Storage - value: storage - required: true - schema: - $ref: discriminator#/properties/autoscalingType - type: radio - - discriminator: - topologyMachines: - default: [] - type: array + - text: 'Yes' + value: 'yes' + - text: 'No' + value: 'no' + if: + type: function + name: showScheduleBackup + init: + type: func + value: initScheduleBackupForEdit + watcher: + func: onScheduleBackupChange + paths: + - temp/properties/scheduleBackup + - type: block-layout + label: Backup Form + showLabels: false + loader: initBackupData + if: + type: function + name: showBackupForm elements: - - fetch: fetchTopologyMachines - if: returnFalse - schema: - $ref: discriminator#/topologyMachines - type: input - - elements: - - computed: setTrigger|autoscalingKubedbComZooKeeperAutoscaler/spec/compute/zookeeper/trigger - label: - text: Trigger + - type: radio + label: Select Backup Type + schema: temp/properties/backupType + isHorizontal: true options: - - "On" - - "Off" - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/trigger - type: select - - label: - text: Pod LifeTime Threshold - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/podLifeTimeThreshold - type: input - - label: - text: Resource Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/resourceDiffPercentage - type: input - - discriminator: - allowedMachine-max: - type: string - allowedMachine-min: - type: string + - text: BackupConfig + value: BackupConfig + description: 'Create, Delete or Modify BackupConfig' + - text: BackupBlueprint + value: BackupBlueprint + description: Enable/Disable BackupBlueprint + if: + type: function + name: isBackupDataLoadedTrue + init: + type: func + value: setBackupType + loader: getTypes + watcher: + func: onBackupTypeChange + paths: + - temp/properties/backupType + - type: block-layout + label: Config + if: + type: function + name: isBackupType|BackupConfig elements: - - computed: setAllowedMachine|min - disableUnselect: true - fetch: getMachines|min - if: hasAnnotations - label: - text: Min Allowed Profile - onChange: onMachineChange|zookeeper - schema: - $ref: discriminator#/properties/allowedMachine-min - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/minAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/minAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Min Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/minAllowed - show_label: true - type: single-step-form - - computed: setAllowedMachine|max - disableUnselect: true - fetch: getMachines|max - if: hasAnnotations - label: - text: Max Allowed Profile - onChange: onMachineChange|zookeeper - schema: - $ref: discriminator#/properties/allowedMachine-max - type: select - - elements: - - label: - text: cpu - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/maxAllowed/properties/cpu - type: input - - label: - text: memory - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/maxAllowed/properties/memory - type: input - if: hasNoAnnotations - label: - text: Max Allowed - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/maxAllowed - show_label: true - type: single-step-form - type: single-step-form - - fetch: setControlledResources|zookeeper - label: - text: Controlled Resources - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/controlledResources - type: multiselect - label: - text: Zookeeper - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper - show_label: true - type: single-step-form - - elements: - - fetch: fetchNodeTopology - label: - text: Select Node Topology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name - type: select - - if: isNodeTopologySelected - label: - text: ScaleUp Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage - type: input - - if: isNodeTopologySelected - label: - text: ScaleDown Diff Percentage - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage - type: input - if: hasNoAnnotations - label: - text: NodeTopology - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/nodeTopology - show_label: true - type: single-step-form - type: single-step-form - - elements: - - label: - text: Timeout - options: - - text: 5 minutes - value: 5m0s - - text: 10 minutes - value: 10m0s - - text: 30 minutes - value: 30m0s - - text: 1 hour - value: 1h0m - - text: 2 hours - value: 2h0m - - text: 5 hours - value: 5h0m - - text: 10 hours - value: 10h0m - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: Apply + - type: select + label: Select Context + schema: temp/properties/backupConfigContext + validation: + type: required + loader: getContext + watcher: + func: onContextChange + paths: + - temp/properties/backupConfigContext + - type: select + label: Select BackupConfig + schema: temp/properties/config + validation: + type: required + if: + type: function + name: showConfigList + loader: getConfigList + watcher: + func: onConfigChange + paths: + - temp/properties/config + - type: input + label: Schedule + schema: temp/properties/schedule + validation: + type: required + if: + type: function + name: showSchedule + loader: + name: getDefaultSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions + watchPaths: + - temp/properties/config + watcher: + func: onInputChangeSchedule|/resources/coreKubestashComBackupConfiguration/spec/sessions|schedule + paths: + - temp/properties/schedule + - type: switch + label: Paused + schema: schema/properties/resources/properties/coreKubestashComBackupConfiguration/properties/spec/properties/paused + if: + type: function + name: showPause + - type: block-layout + label: Blueprint + if: + type: function + name: isBackupType|BackupBlueprint + elements: + - type: switch + label: Enable Backup Blueprint + schema: temp/properties/blueprintEnabled + init: + type: func + value: setBlueprintSwitch + watcher: + func: onBlueprintChange + paths: + - temp/properties/blueprintEnabled + - type: block-layout + label: Archiver + if: + type: function + name: isBackupType|Archiver + elements: + - type: switch + label: Enable Archiver + schema: temp/properties/archiverEnabled + init: + type: func + value: setArchiverSwitch + watcher: + func: onArchiverChange + paths: + - temp/properties/archiverEnabled + - type: single-step-form + id: compute-autoscaler + loader: getDbDetails + elements: + - type: block-layout + if: + type: function + name: isConsole + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/metadata/properties/name + - type: select + label: Select Namespace + loader: getNamespaces + if: + type: function + name: isRancherManaged + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/metadata/properties/namespace + - type: select + label: Select Db + loader: getDbs + validation: + type: required + refresh: true + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/databaseRef/properties/name + watcher: + func: initMetadata + paths: + - schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/databaseRef/properties/name + + - type: radio + if: + type: function + name: isConsole + label: Select Type + validation: + type: required + schema: temp/properties/autoscalingType + watcher: + func: initMetadata + paths: + - temp/properties/autoscalingType options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply - type: radio - if: showOpsRequestOptions - label: - text: Ops Request Options - schema: - $ref: schema#/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/opsRequestOptions - show_label: true - type: single-step-form - type: single-step-form - id: compute-autoscaler - title: steps.6.label -- form: - discriminator: - enableMonitoring: - default: true - type: boolean + - text: Compute + value: compute + description: Scale your CPU Memory based on resource usage + - text: Storage + value: storage + description: Expand your database size based on volume usage + + - type: block-layout + showLabels: false + loader: fetchTopologyMachines + elements: + # zookeeper mode + - type: block-layout + label: Zookeeper + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper + elements: + - type: select + label: Trigger + init: + type: func + value: setTrigger|autoscalingKubedbComZooKeeperAutoscaler/spec/compute/zookeeper/trigger + options: + - text: 'On' + value: 'On' + - text: 'Off' + value: 'Off' + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/trigger + - type: input + label: Pod LifeTime Threshold + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/podLifeTimeThreshold + - type: input + label: Resource Diff Percentage + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/resourceDiffPercentage + - type: block-layout + showLabels: false + elements: + - type: horizontal-layout + elements: + - type: machine-compare + label: Min Allowed Profile + schema: temp/properties/allowedMachine-min + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|min + loader: + name: getMachines|min + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-max + watcher: + func: onMachineChange|zookeeper + paths: + - temp/properties/allowedMachine-min + - type: block-layout + label: Min Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/minAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/minAllowed/properties/memory + - type: machine-compare + label: Max Allowed Profile + schema: temp/properties/allowedMachine-max + if: + type: function + name: hasAnnotations + init: + type: func + value: setAllowedMachine|max + loader: + name: getMachines|max + watchPaths: + - temp/properties/topologyMachines + - temp/properties/allowedMachine-min + watcher: + func: onMachineChange|zookeeper + paths: + - temp/properties/allowedMachine-max + - type: block-layout + label: Max Allowed + if: + type: function + name: hasNoAnnotations + showLabels: true + elements: + - type: input-compare + label: Cpu + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/maxAllowed/properties/cpu + - type: input-compare + label: Memory + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/maxAllowed/properties/memory + - type: select + label: Controlled Resources + loader: setControlledResources|zookeeper + multiple: true + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/zookeeper/properties/controlledResources + + - type: block-layout + label: Node Topology + if: + type: function + name: hasNoAnnotations + showLabels: true + # schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/nodeTopology + elements: + - type: select + label: Select Node Topology + loader: fetchNodeTopology + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/name + - type: input + label: ScaleUp Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleUpDiffPercentage + - type: input + label: ScaleDown Diff Percentage + if: + type: function + name: isNodeTopologySelected + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/compute/properties/nodeTopology/properties/scaleDownDiffPercentage + + - type: block-layout + label: Ops Request Options + showLabels: true + if: + type: function + name: showOpsRequestOptions + # schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/opsRequestOptions + elements: + - type: select + label: Timeout + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/opsRequestOptions/properties/timeout + options: + - text: 5 minutes + value: 5m0s + - text: 10 minutes + value: 10m0s + - text: 30 minutes + value: 30m0s + - text: 1 hour + value: 1h0m + - text: 2 hours + value: 2h0m + - text: 5 hours + value: 5h0m + - text: 10 hours + value: 10h0m + - type: radio + label: Apply + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always + schema: schema/properties/resources/properties/autoscalingKubedbComZooKeeperAutoscaler/properties/spec/properties/opsRequestOptions/properties/apply + - type: single-step-form + id: monitoring elements: - - label: - text: labels.to_update_exporter_resources - type: label-element - - customClass: mb-20 - label: - text: labels.create_opsrequest - type: anchor - url: - function: getOpsRequestUrl|VerticalScaling - - computed: isValueExistInModel|/resources/kubedbComZooKeeper/spec/monitor - label: - text: labels.enable_monitoring - onChange: onEnableMonitoringChange - schema: - $ref: discriminator#/enableMonitoring - type: switch - - discriminator: - customizeExporter: - default: true - type: boolean + - type: label-element + label: To update Exporter Resource section click on Create OpsRequest + - type: anchor + label: Create OpsRequest + schema: temp/properties/opsRequestUrl + init: + type: func + value: getOpsRequestUrl|VerticalScaling + - type: switch + label: Enable Monitoring + schema: temp/properties/enableMonitoring + init: + type: func + value: isValueExistInModel|/resources/kubedbComZooKeeper/spec/monitor + watcher: + func: onEnableMonitoringChange + paths: + - temp/properties/enableMonitoring + - type: block-layout + label: Backup form + showLabels: false + if: + type: function + name: showMonitoringSection elements: - - hasDescription: true - label: - text: labels.agent - onChange: onAgentChange - options: - - description: options.agent.prometheus_operator.description - text: options.agent.prometheus_operator.label - value: prometheus.io/operator - - description: options.agent.prometheus.description - text: options.agent.prometheus.label - value: prometheus.io - - description: options.agent.prometheus_builtin.description - text: options.agent.prometheus_builtin.label - value: prometheus.io/builtin - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/agent - type: radio - - elements: - - label: - text: labels.scrapping_interval - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval - type: input - if: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComZooKeeper/spec/monitor/agent - label: - text: labels.service_monitor_configuration - show_label: true - type: single-step-form - - elements: - - elements: - - addFormLabel: labels.endpoint - element: - elements: - - label: - text: labels.honor_labels - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/honorLabels - type: switch - - label: - text: labels.interval - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/interval - type: input - - label: - text: labels.path - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/path - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints/items/properties/port - type: input - type: single-step-form - label: - text: labels.endpoints - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints - tableContents: - - inTableColumn: true - label: - text: labels.honor_labels - path: honorLabels - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.interval - path: interval - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.path - path: path - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.port - path: port - type: value - typeOfValue: string - type: single-step-form-array - - elements: - - fetch: getResources|core|v1|namespaces - label: - text: labels.matchNames - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames - type: multiselect - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector - type: single-step-form - - elements: - - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels/additionalProperties + - type: radio + label: Select a Monitoring Method + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/agent + isHorizontal: true + options: + - text: Prometheus Operator + value: prometheus.io/operator + description: Inject metric exporter sidecar and creates a ServiceMonitor + - text: Custom ServiceMonitor + value: prometheus.io + description: Injects the metric exporter sidecar and let you customize ServiceMonitor + - text: Custom Scrapper + value: prometheus.io/builtin + description: Inject metric exporter sidecar and add Prometheus annotations to the stats Service + init: + type: static + value: prometheus.io/operator + watcher: + func: onAgentChange + paths: + - schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/agent + - type: block-layout + label: ServiceMonitor Configuration + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io/operator|/resources/kubedbComZooKeeper/spec/monitor/agent + elements: + - label: Scrapping Interval + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/serviceMonitor/properties/interval + type: input + - type: block-layout + label: Service Monitor + showLabels: true + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComZooKeeper/spec/monitor/agent + elements: + - type: array-object-form + label: Endpoints + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/endpoints + elements: + - type: switch + label: Honor labels + schema: honorLabels + - type: input + label: Interval + schema: interval + - type: input + label: Path + schema: path + - type: input + label: Port + schema: port + - type: select + multiple: true + label: Match Namespaces + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/namespaceSelector/properties/matchNames + loader: getResources|core|v1|namespaces + if: + type: function + name: returnFalse + - type: block-layout + showLabels: false + # schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector + if: + type: function + name: returnFalse + elements: + - type: object-item + label: Labels + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector/properties/matchLabels + - type: object-item + schema: schema/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels + label : Labels + if: + type: function + name: isEqualToModelPathValue|prometheus.io|/resources/kubedbComZooKeeper/spec/monitor/agent + # individualItemDisabilityCheck: disableLableChecker + - type: label-element + label: Exporter Configuration + schema: '' + - type: switch + label: Customize Exporter Sidecar + schema: temp/properties/customizeExporter + init: + type: static + value: true + watcher: + func: onCustomizeExporterChange + paths: + - temp/properties/customizeExporter + - type: block-layout + label: Customer Exporter Section + showLabels: false + if: + type: function + name: showCustomizeExporterSection + elements: + - type: machine-compare + label: Resources + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources + if: + type: function + name: returnFalse + - type: label-element + label: Security Context + schema: '' + - type: input + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser + label: Run as User + - type: input + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup + label: Run as Group + - type: input + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port + label: Port + - type: array-item-form + label: Args + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args + init: + type: static + value: ['--compatible-mode'] + element: type: input - if: returnFalse - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec/properties/selector - type: single-step-form - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/spec - type: single-step-form - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComZooKeeper/spec/monitor/agent - label: - text: labels.service_monitor - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor - show_label: true - type: single-step-form - - if: isEqualToModelPathValue|prometheus.io|/resources/kubedbComZooKeeper/spec/monitor/agent - individualItemDisabilityCheck: disableLableChecker - isArray: true - keys: - label: - text: labels.labels.key - label: - text: labels.labels.label - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels - type: key-value-input-form - values: - label: - text: labels.labels.value - schema: - $ref: schema#/properties/resources/properties/monitoringCoreosComServiceMonitor/properties/metadata/properties/labels/additionalProperties - type: input - - label: - text: labels.exporter_configuration - type: label-element - - label: - text: labels.customize_exporter - onChange: onCustomizeExporterChange - schema: - $ref: discriminator#/customizeExporter - type: switch - - elements: - - if: returnFalse - label: - text: labels.resources - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/resources - type: resource-input-form - - label: - text: labels.security_context - type: label-element - - label: - text: labels.run_as_user - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsUser - type: input - - customClass: mb-0 - label: - text: labels.run_as_group - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/securityContext/properties/runAsGroup - type: input - - label: - text: labels.port - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/port - type: input - - element: - label: - isSubsection: true - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args/items - type: input - label: - text: labels.args - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/args - type: list-input-form - - alias: reusable_env - chart: - name: uibytebuildersdev-component-env - version: v0.27.0 - dataContext: - namespace: - $ref: schema#/properties/metadata/properties/release/properties/namespace - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env - type: reusable-element - if: showCustomizeExporterSection - type: single-step-form - if: showMonitoringSection - type: single-step-form - type: single-step-form - id: monitoring - title: steps.5.label -type: multi-step-form + label: Args + schema: items + # isSubsection: true + - type: block-layout + label: Metadata + showLabels: false + elements: + #remove: should be array-object-form after fixes + - type: block-layout + label: New Environment Variable + showLabels: true + hideBlock: true + # schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env + elements: + - type: input + label: Name + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/name + - type: radio + label: Value From + schema: temp/properties/valueFromType + init: + type: func + value: setValueFrom + options: + - text: Input + value: input + - text: Secret + value: secret + - text: ConfigMap + value: configMap + watcher: + func: onValueFromChange + paths: + - temp/properties/valueFromType + - type: input + label: Value + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/value + if: + name: isEqualToValueFromType|input + type: function + - type: select + if: + type: function + name: isEqualToValueFromType|configMap + label: ConfigMap Name + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/name + loader: + name: resourceNames|core|v1|configmaps + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: ConfigMap Key + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/configMapKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|configMap + loader: + name: getConfigMapKeys + watchPaths: + - schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/configMapKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Name + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/name + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecrets + watchPaths: + - schema/metadata/release/namespace + # allowUserDefinedOption: true + - type: select + label: Secret Key + schema: schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/properties/valueFrom/properties/secretKeyRef/properties/key + if: + type: function + name: isEqualToValueFromType|secret + loader: + name: getSecretKeys + watchPaths: + - schema/properties/resources/properties/kubedbComZooKeeper/properties/spec/properties/monitor/properties/prometheus/properties/exporter/properties/env/properties/items/valueFrom/secretKeyRef/name + - schema/metadata/release/namespace + # allowUserDefinedOption: true \ No newline at end of file diff --git a/charts/kubedbcom-zookeeper-editor/ui/functions.js b/charts/kubedbcom-zookeeper-editor/ui/functions.js index 8c37583e7c..80f6eddbd3 100644 --- a/charts/kubedbcom-zookeeper-editor/ui/functions.js +++ b/charts/kubedbcom-zookeeper-editor/ui/functions.js @@ -1,877 +1,866 @@ -// backup form -function showBackupForm({ getValue, discriminator, watchDependency }) { - const scheduleBackup = getValue(discriminator, '/scheduleBackup') - watchDependency('discriminator#/scheduleBackup') +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} - if (scheduleBackup === 'yes') return true - else return false -} - -let initialModel = {} -let isBackupOn = false -let isBackupOnModel = false -let dbResource = {} -let initialDbMetadata = {} -let namespaceList = [] -let backupConfigurationsFromStore = {} -let valuesFromWizard = {} -let initialArchiver = {} -let isArchiverAvailable = false -let archiverObjectToCommit = {} - -async function initBackupData({ storeGet, axios, getValue, model, setDiscriminatorValue }) { - // set initial model for further usage - initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') - isBackupOnModel = !!initialModel - - // check db backup is enabled or not - backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') - const configs = objectCopy(backupConfigurationsFromStore) - const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - dbResource = getValue(model, '/resources/kubedbComZooKeeper') - initialDbMetadata = objectCopy(dbResource.metadata) - - // get values.yaml to populate data when backup-config is being created - try { - const actionArray = storeGet('/resource/actions/result') - const editorDetails = actionArray[0]?.items[0]?.editor - const chartName = editorDetails?.name - const sourceApiGroup = editorDetails?.sourceRef?.apiGroup - const sourceKind = editorDetails?.sourceRef?.kind - const sourceNamespace = editorDetails?.sourceRef?.namespace - const sourceName = editorDetails?.sourceRef?.name - const chartVersion = editorDetails?.version - - let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - if (spoke) - url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` - - const resp = await axios.get(url) - - valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} - } catch (e) { - console.log(e) - } - - // check config with metadata name first - let config = configs?.find( - (item) => - item.metadata?.name === name && - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, +// ************************* common functions ******************************************** +// eslint-disable-next-line no-empty-pattern +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, ) - // check config without metadata name if not found with metadata name - if (!config) - config = configs?.find( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, + /********** Initialize Discriminator **************/ + + setDiscriminatorValue('repoInitialSelectionStatus', '') + setDiscriminatorValue('scheduleBackup', 'yes') + setDiscriminatorValue('backupType', '') + setDiscriminatorValue('isBackupDataLoaded', false) + setDiscriminatorValue('backupConfigContext', '') + setDiscriminatorValue('config', '') + setDiscriminatorValue('paused', false) + setDiscriminatorValue('schedule', '') + setDiscriminatorValue('blueprintEnabled', false) + setDiscriminatorValue('archiverEnabled', false) + + setDiscriminatorValue('binding', false) + setDiscriminatorValue('hidePreviewFromWizard', undefined) + + setDiscriminatorValue('/enableMonitoring', false) + setDiscriminatorValue('/customizeExporter', true) + setDiscriminatorValue('/valueFromType', 'input') + + // Compute Autoscaler Discriminators + setDiscriminatorValue('/dbDetails', false) + setDiscriminatorValue('/topologyMachines', []) + + function initScheduleBackupForEdit() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, ) - // set backup switch here - isBackupOn = !!config + initRepositoryChoiseForEdit() - // set initial data from stash-presets - const stashPreset = storeGet('/backup/stashPresets') - if (stashPreset) { - const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset - - const tempBackends = valuesFromWizard.spec?.backends - tempBackends[0]['storageRef'] = storageRef - tempBackends[0]['retentionPolicy'] = retentionPolicy - valuesFromWizard.spec['backends'] = tempBackends + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' + } - const tempSessions = valuesFromWizard.spec?.sessions - const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories - tempRepositories[0]['encryptionSecret'] = encryptionSecret - tempRepositories[0].name = name - tempRepositories[0]['directory'] = `${namespace}/${name}` + function initScheduleBackup() { + const { stashAppscodeComBackupConfiguration, isBluePrint } = getBackupConfigsAndAnnotations( + getValue, + model, + ) - tempSessions[0]['repositories'] = tempRepositories - tempSessions[0]['scheduler']['schedule'] = schedule - valuesFromWizard.spec['sessions'] = tempSessions + if (stashAppscodeComBackupConfiguration || isBluePrint) return 'yes' + else return 'no' } - const apiGroup = storeGet('/route/params/group') - valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } - const labels = dbResource.metadata?.labels - valuesFromWizard['metadata'] = { - name: `${name}-${Math.floor(Date.now() / 1000)}`, - namespace, - labels, + // backup form + function showBackupForm() { + const scheduleBackup = getValue(discriminator, '/scheduleBackup') + // watchDependency('discriminator#/scheduleBackup') + if (scheduleBackup === 'yes') return true + else return false } - setDiscriminatorValue('isBackupDataLoaded', true) -} + let initialModel = {} + let isBackupOn = false + let isBackupOnModel = false + let dbResource = {} + let initialDbMetadata = {} + let backupConfigurationsFromStore = {} + let valuesFromWizard = {} + let initialArchiver = {} + let isArchiverAvailable = false + let archiverObjectToCommit = {} + + async function initBackupData() { + // set initial model for further usage + initialModel = getValue(model, '/resources/coreKubestashComBackupConfiguration') + isBackupOnModel = !!initialModel + + // check db backup is enabled or not + backupConfigurationsFromStore = storeGet('/backup/backupConfigurations') + const configs = objectCopy(backupConfigurationsFromStore) + const { name, cluster, user, group, resource, spoke } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + dbResource = getValue(model, '/resources/kubedbComZooKeeper') + initialDbMetadata = objectCopy(dbResource.metadata) + initialArchiver = dbResource.spec?.archiver ? objectCopy(dbResource.spec?.archiver) : undefined -function isBackupDataLoadedTrue({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/isBackupDataLoaded') - return !!getValue(discriminator, '/isBackupDataLoaded') -} + // get values.yaml to populate data when backup-config is being created + try { + const actionArray = storeGet('/resource/actions/result') + const editorDetails = actionArray[0]?.items[0]?.editor + const chartName = editorDetails?.name + const sourceApiGroup = editorDetails?.sourceRef?.apiGroup + const sourceKind = editorDetails?.sourceRef?.kind + const sourceNamespace = editorDetails?.sourceRef?.namespace + const sourceName = editorDetails?.sourceRef?.name + const chartVersion = editorDetails?.version -async function setBackupType() { - return 'BackupConfig' -} + let url = `/clusters/${user}/${cluster}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` -async function getTypes() { - const arr = [ - { - description: 'Create, Delete or Modify BackupConfig', - text: 'BackupConfig', - value: 'BackupConfig', - }, - { - description: 'Enable/Disable BackupBlueprint', - text: 'BackupBlueprint', - value: 'BackupBlueprint', - }, - ] - - return arr -} + if (spoke) + url = `/clusters/${user}/${spoke}/helm/packageview/values?name=${chartName}&sourceApiGroup=${sourceApiGroup}&sourceKind=${sourceKind}&sourceNamespace=${sourceNamespace}&sourceName=${sourceName}&version=${chartVersion}&format=json` -function onBackupTypeChange({ commit, getValue, discriminator }) { - const type = getValue(discriminator, '/backupType') - commit('wizard/model$update', { - path: '/backupType', - value: type, - force: true, - }) - if (!isBackupOnModel) { - commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') - } else { - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: objectCopy(initialModel), - force: true, - }) - } - commit('wizard/model$delete', '/context') - commit('wizard/model$update', { - path: '/resources/kubedbComZooKeeper', - value: objectCopy(dbResource), - force: true, - }) -} + const resp = await axios.get(url) -function isBackupType({ watchDependency, getValue, discriminator }, type) { - watchDependency('discriminator#/backupType') - const selectedType = getValue(discriminator, '/backupType') + valuesFromWizard = objectCopy(resp.data?.resources?.coreKubestashComBackupConfiguration) || {} + } catch (e) { + console.log(e) + } - return selectedType === type -} + // check storageclass archiver annotation + if (initialArchiver) { + isArchiverAvailable = true + } else { + const storageClassName = dbResource?.spec?.storage?.storageClassName + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses/${storageClassName}` + try { + const resp = await axios.get(url) + const archAnnotation = resp.data?.metadata?.annotations + const annotationKeyToFind = `${resource}.${group}/archiver` + if (archAnnotation[annotationKeyToFind]) { + isArchiverAvailable = true + archiverObjectToCommit = { + ref: { + name: archAnnotation[annotationKeyToFind], + namespace: 'kubedb', + }, + } + } + } catch (e) { + console.log(e) + } + } -function setBlueprintSwitch() { - const annotations = initialDbMetadata?.annotations + // check config with metadata name first + let config = configs?.find( + (item) => + item.metadata?.name === name && + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) - return !!( - annotations['blueprint.kubestash.com/name'] && annotations['blueprint.kubestash.com/namespace'] - ) -} + // check config without metadata name if not found with metadata name + if (!config) + config = configs?.find( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) -function onBlueprintChange({ getValue, discriminator, commit, model, storeGet }) { - const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') - if (blueprintSwitch) addLabelAnnotation(commit, storeGet, 'annotations') - else deleteLabelAnnotation(commit, 'annotations') -} + // set backup switch here + isBackupOn = !!config -function setArchiverSwitch() { - const archiver = dbResource?.spec?.archiver - return !!archiver -} + // set initial data from stash-presets + const stashPreset = storeGet('/backup/stashPresets') + if (stashPreset) { + const { retentionPolicy, encryptionSecret, schedule, storageRef } = stashPreset -function onArchiverChange({ getValue, discriminator, commit }) { - const archiverSwitch = getValue(discriminator, '/archiverEnabled') - const path = 'resources/kubedbComZooKeeper/spec/archiver' - if (archiverSwitch) { - commit('wizard/model$update', { - path: path, - value: initialArchiver ? initialArchiver : archiverObjectToCommit, - }) - } else { - commit('wizard/model$delete', path) - } -} + const tempBackends = valuesFromWizard.spec?.backends + tempBackends[0]['storageRef'] = storageRef + tempBackends[0]['retentionPolicy'] = retentionPolicy + valuesFromWizard.spec['backends'] = tempBackends -function addLabelAnnotation(commit, storeGet, type) { - const obj = objectCopy(initialDbMetadata[type]) + const tempSessions = valuesFromWizard.spec?.sessions + const tempRepositories = valuesFromWizard.spec?.sessions[0]?.repositories + tempRepositories[0]['encryptionSecret'] = encryptionSecret + tempRepositories[0].name = name + tempRepositories[0]['directory'] = `${namespace}/${name}` - if (type === 'annotations') { - const kind = storeGet('/resource/layout/result/resource/kind') - obj['blueprint.kubestash.com/name'] = 'kubedb' - obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` - } else { - obj['kubedb.com/archiver'] = 'true' - } + tempSessions[0]['repositories'] = tempRepositories + tempSessions[0]['scheduler']['schedule'] = schedule + valuesFromWizard.spec['sessions'] = tempSessions + } - commit('wizard/model$update', { - path: `/resources/kubedbComZooKeeper/metadata/${type}`, - value: obj, - force: true, - }) -} + const apiGroup = storeGet('/route/params/group') + valuesFromWizard.spec['target'] = { name, namespace, apiGroup, kind } + const labels = dbResource.metadata?.labels + valuesFromWizard['metadata'] = { + name: `${name}-${Math.floor(Date.now() / 1000)}`, + namespace, + labels, + } -function deleteLabelAnnotation(commit, type) { - const obj = initialDbMetadata[type] + setDiscriminatorValue('isBackupDataLoaded', true) + } - if (type === 'annotations') { - delete obj['blueprint.kubestash.com/name'] - delete obj['blueprint.kubestash.com/namespace'] - } else delete obj['kubedb.com/archiver'] + function isBackupDataLoadedTrue() { + // watchDependency('discriminator#/isBackupDataLoaded') + return !!getValue(discriminator, '/isBackupDataLoaded') + } - commit('wizard/model$update', { - path: `/resources/kubedbComZooKeeper/metadata/${type}`, - value: obj, - force: true, - }) -} + function setBackupType() { + return 'BackupConfig' + } -function getContext() { - if (isBackupOn) return ['Create', 'Delete', 'Modify'] - return ['Create'] -} + function getTypes() { + const arr = [ + { + description: 'Create, Delete or Modify BackupConfig', + text: 'BackupConfig', + value: 'BackupConfig', + }, + { + description: 'Enable/Disable BackupBlueprint', + text: 'BackupBlueprint', + value: 'BackupBlueprint', + }, + ] + + if ((dbResource?.spec?.replicaSet || dbResource?.spec?.shardTopology) && isArchiverAvailable) { + arr.push({ + description: 'Enable/Disable Archiver', + text: 'Archiver', + value: 'Archiver', + }) + } + return arr + } -function onContextChange({ getValue, discriminator, commit, model }) { - const context = getValue(discriminator, '/backupConfigContext') - commit('wizard/model$update', { - path: '/context', - value: context, - force: true, - }) - if (context === 'Create') { + function onBackupTypeChange() { + const type = getValue(discriminator, '/backupType') commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: valuesFromWizard, + path: '/backupType', + value: type, + force: true, + }) + if (!isBackupOnModel) { + commit('wizard/model$delete', '/resources/coreKubestashComBackupConfiguration') + } else { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: objectCopy(initialModel), + force: true, + }) + } + commit('wizard/model$delete', '/context') + commit('wizard/model$update', { + path: '/resources/kubedbComZooKeeper', + value: objectCopy(dbResource), force: true, }) } -} -function getConfigList({ storeGet }) { - const configs = objectCopy(backupConfigurationsFromStore) - const { name, group } = storeGet('/route/params') - const namespace = storeGet('/route/query/namespace') - const kind = storeGet('/resource/layout/result/resource/kind') - const filteredList = configs?.filter( - (item) => - item.spec?.target?.name === name && - item.spec?.target?.namespace === namespace && - item.spec?.target?.kind === kind && - item.spec?.target?.apiGroup === group, - ) - const list = filteredList?.map((ele) => ele.metadata.name) - return list -} + function isBackupType(type) { + // watchDependency('discriminator#/backupType') + const selectedType = getValue(discriminator, '/backupType') -function onConfigChange({ getValue, discriminator, commit, storeGet, model }) { - const configName = getValue(discriminator, '/config') - const configs = objectCopy(backupConfigurationsFromStore) - const configDetails = configs?.find((item) => item?.metadata?.name === configName) - - commit('wizard/model$update', { - path: '/resources/coreKubestashComBackupConfiguration', - value: configDetails, - force: true, - }) -} - -function showPause({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const contex = getValue(discriminator, '/backupConfigContext') - const configName = getValue(discriminator, '/config') - return !!configName && contex === 'Modify' -} - -function showConfigList({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - const contex = getValue(discriminator, '/backupConfigContext') - return contex === 'Modify' || contex === 'Delete' -} + return selectedType === type + } -function showSchedule({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/backupConfigContext') - watchDependency('discriminator#/config') - const configName = getValue(discriminator, '/config') - const contex = getValue(discriminator, '/backupConfigContext') - if (contex === 'Create') return true - else if (contex === 'Delete') return false - else return !!configName -} + function setBlueprintSwitch() { + const annotations = initialDbMetadata?.annotations -function onInputChangeSchedule( - { getValue, discriminator, commit, model }, - modelPath, - discriminatorName, -) { - const value = getValue(discriminator, `/${discriminatorName}`) - const session = getValue(model, modelPath) - session[0].scheduler.schedule = value - commit('wizard/model$update', { - path: modelPath, - value: session, - }) -} + return !!( + annotations['blueprint.kubestash.com/name'] && + annotations['blueprint.kubestash.com/namespace'] + ) + } -function getDefaultSchedule({ getValue, model, watchDependency }, modelPath) { - watchDependency('discriminator#/config') - const session = getValue(model, modelPath) - return session?.length ? session[0]?.scheduler.schedule : '' -} + function onBlueprintChange() { + const blueprintSwitch = getValue(discriminator, '/blueprintEnabled') + if (blueprintSwitch) addLabelAnnotation('annotations') + else deleteLabelAnnotation('annotations') + } -function objectCopy(obj) { - const temp = JSON.stringify(obj) - return JSON.parse(temp) -} + function setArchiverSwitch() { + const archiver = dbResource?.spec?.archiver + return !!archiver + } -function returnFalse() { - return false -} + function onArchiverChange() { + const archiverSwitch = getValue(discriminator, '/archiverEnabled') + const path = 'resources/kubedbComZooKeeper/spec/archiver' + if (archiverSwitch) { + commit('wizard/model$update', { + path: path, + value: initialArchiver ? initialArchiver : archiverObjectToCommit, + }) + } else { + commit('wizard/model$delete', path) + } + } -function isValueExistInModel({ model, getValue }, path) { - const modelValue = getValue(model, path) - return !!modelValue -} + function addLabelAnnotation(type) { + const obj = objectCopy(initialDbMetadata[type]) -function showMonitoringSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/enableMonitoring') - const configureStatus = getValue(discriminator, '/enableMonitoring') - return configureStatus -} + if (type === 'annotations') { + const kind = storeGet('/resource/layout/result/resource/kind') + obj['blueprint.kubestash.com/name'] = 'kubedb' + obj['blueprint.kubestash.com/namespace'] = `${kind.toLowerCase()}-blueprint` + } else { + obj['kubedb.com/archiver'] = 'true' + } -function onEnableMonitoringChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/enableMonitoring') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComZooKeeper/spec/monitor', - value: {}, + path: `/resources/kubedbComZooKeeper/metadata/${type}`, + value: obj, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComZooKeeper/spec/monitor') } - // update alert value depend on monitoring profile - commit('wizard/model$update', { - path: '/form/alert/enabled', - value: configureStatus ? 'warning' : 'none', - force: true, - }) -} + function deleteLabelAnnotation(type) { + const obj = initialDbMetadata[type] -function showCustomizeExporterSection({ watchDependency, discriminator, getValue }) { - watchDependency('discriminator#/customizeExporter') - const configureStatus = getValue(discriminator, '/customizeExporter') - return configureStatus -} + if (type === 'annotations') { + delete obj['blueprint.kubestash.com/name'] + delete obj['blueprint.kubestash.com/namespace'] + } else delete obj['kubedb.com/archiver'] -function onCustomizeExporterChange({ discriminator, getValue, commit }) { - const configureStatus = getValue(discriminator, '/customizeExporter') - if (configureStatus) { commit('wizard/model$update', { - path: '/resources/kubedbComZooKeeper/spec/monitor/prometheus/exporter', - value: {}, + path: `/resources/kubedbComZooKeeper/metadata/${type}`, + value: obj, force: true, }) - } else { - commit('wizard/model$delete', '/resources/kubedbComZooKeeper/spec/monitor/prometheus/exporter') } -} -function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) { - const modelPathValue = getValue(model, modelPath) - watchDependency('model#' + modelPath) - return modelPathValue === value -} + function getContext() { + if (isBackupOn) return ['Create', 'Delete', 'Modify'] + return ['Create'] + } -function setMetadata({ storeGet, mode, commit }) { - const dbname = storeGet('/route/params/name') || '' - const namespace = storeGet('/route/query/namespace') || '' - if (mode === 'standalone-step') { + function onContextChange() { + const context = getValue(discriminator, '/backupConfigContext') commit('wizard/model$update', { - path: '/metadata/release/name', - value: dbname, + path: '/context', + value: context, force: true, }) + if (context === 'Create') { + commit('wizard/model$update', { + path: '/resources/coreKubestashComBackupConfiguration', + value: valuesFromWizard, + force: true, + }) + } + if (context === 'Delete') setDiscriminatorValue('hidePreviewFromWizard', true) + else setDiscriminatorValue('hidePreviewFromWizard', undefined) + } + + function getConfigList() { + const configs = objectCopy(backupConfigurationsFromStore) + const { name, group } = storeGet('/route/params') + const namespace = storeGet('/route/query/namespace') + const kind = storeGet('/resource/layout/result/resource/kind') + const filteredList = configs?.filter( + (item) => + item.spec?.target?.name === name && + item.spec?.target?.namespace === namespace && + item.spec?.target?.kind === kind && + item.spec?.target?.apiGroup === group, + ) + const list = filteredList?.map((ele) => ele.metadata.name) + return list + } + + function onConfigChange() { + const configName = getValue(discriminator, '/config') + const configs = objectCopy(backupConfigurationsFromStore) + const configDetails = configs?.find((item) => item?.metadata?.name === configName) + commit('wizard/model$update', { - path: '/metadata/release/namespace', - value: namespace, + path: '/resources/coreKubestashComBackupConfiguration', + value: configDetails, force: true, }) } -} -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + function showPause() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const contex = getValue(discriminator, '/backupConfigContext') + const configName = getValue(discriminator, '/config') + return !!configName && contex === 'Modify' + } - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) + function showConfigList() { + // watchDependency('discriminator#/backupConfigContext') + const contex = getValue(discriminator, '/backupConfigContext') + return contex === 'Modify' || contex === 'Delete' } - return { - ui: ui.data || {}, - language: language.data || {}, - functions, + function showSchedule() { + // watchDependency('discriminator#/backupConfigContext') + // watchDependency('discriminator#/config') + const configName = getValue(discriminator, '/config') + const contex = getValue(discriminator, '/backupConfigContext') + if (contex === 'Create') return true + else if (contex === 'Delete') return false + else return !!configName } -} -function onAgentChange({ commit, model, getValue }) { - const agent = getValue(model, '/resources/kubedbComZooKeeper/spec/monitor/agent') - if (agent === 'prometheus.io') { - commit('wizard/model$update', { - path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', - value: [], - force: true, - }) + function showScheduleBackup() { + const operationQuery = storeGet('/route/params/actions') || '' + const isBackupOperation = operationQuery === 'edit-self-backupconfiguration' ? true : false + return !isBackupOperation + } - onNamespaceChange({ commit, model, getValue }) - onLabelChange({ commit, model, getValue }) - } else { - commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + function getDefaultSchedule(modelPath) { + // watchDependency('discriminator#/config') + const config = getValue(discriminator, '/config') // only for computed behaviour + const session = getValue(model, modelPath) + return session?.length ? session[0]?.scheduler.schedule : '' } -} -function getOpsRequestUrl({ storeGet, model, getValue, mode }, reqType) { - const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - const owner = storeGet('/route/params/user') - const dbname = getValue(model, '/metadata/release/name') - const group = getValue(model, '/metadata/resource/group') - const kind = getValue(model, '/metadata/resource/kind') - const namespace = getValue(model, '/metadata/release/namespace') - const resource = getValue(model, '/metadata/resource/name') - const version = getValue(model, '/metadata/resource/version') - const routeRootPath = storeGet('/route/path') - const pathPrefix = `${domain}/db${routeRootPath}` - const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') - const pathConstructedForKubedb = - pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` - - if (mode === 'standalone-step') return pathConstructedForKubedb - else - return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/zookeeperopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` -} + function initRepositoryChoiseForEdit() { + const stashAppscodeComRepository_repo = getValue( + model, + '/resources/stashAppscodeComRepository_repo', + ) + const repoInitialSelectionStatus = stashAppscodeComRepository_repo ? 'yes' : 'no' + setDiscriminatorValue('/repoInitialSelectionStatus', repoInitialSelectionStatus) -///////////////////////// Autoscaler /////////////////// -let autoscaleType = '' -let dbDetails = {} + return repoInitialSelectionStatus + } -function isConsole({ storeGet, commit }) { - const isKube = isKubedb({ storeGet }) + function onInputChangeSchedule(modelPath, discriminatorName) { + const value = getValue(discriminator, `/${discriminatorName}`) + const session = getValue(model, modelPath) || [] + if (session.length) { + session[0].scheduler.schedule = value + commit('wizard/model$update', { + path: modelPath, + value: session, + }) + } + } - if (isKube) { - const dbName = storeGet('/route/params/name') || '' - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/databaseRef/name', - value: dbName, - force: true, - }) - const operation = storeGet('/route/params/actions') || '' - if (operation.length) { - const splitOp = operation.split('-') - if (splitOp.length > 2) autoscaleType = splitOp[2] + function objectCopy(obj) { + const temp = JSON.stringify(obj) + return JSON.parse(temp) + } + + // monitoring + + function isValueExistInModel(path) { + const modelValue = getValue(model, path) + return !!modelValue + } + + function showMonitoringSection() { + // watchDependency('discriminator#/enableMonitoring') + const configureStatus = getValue(discriminator, '/enableMonitoring') + return configureStatus + } + + function onEnableMonitoringChange() { + const configureStatus = getValue(discriminator, '/enableMonitoring') + if (configureStatus) { + commit('wizard/model$update', { + path: '/resources/kubedbComZooKeeper/spec/monitor', + value: {}, + force: true, + }) + } else { + commit('wizard/model$delete', '/resources/kubedbComZooKeeper/spec/monitor') } - const date = Math.floor(Date.now() / 1000) - const modifiedName = `${dbName}-${date}-autoscaling-${autoscaleType}` + + // update alert value depend on monitoring profile commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/name', - value: modifiedName, + path: '/form/alert/enabled', + value: configureStatus ? 'warning' : 'none', force: true, }) - const namespace = storeGet('/route/query/namespace') || '' - if (namespace) { + } + + function showCustomizeExporterSection() { + // watchDependency('discriminator#/customizeExporter') + const configureStatus = getValue(discriminator, '/customizeExporter') + return configureStatus + } + + function onCustomizeExporterChange() { + const configureStatus = getValue(discriminator, '/customizeExporter') + if (configureStatus) { commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/namespace', - value: namespace, + path: '/resources/kubedbComZooKeeper/spec/monitor/prometheus/exporter', + value: {}, force: true, }) + } else { + commit( + 'wizard/model$delete', + '/resources/kubedbComZooKeeper/spec/monitor/prometheus/exporter', + ) } } - return !isKube -} - -function isKubedb({ storeGet }) { - return !!storeGet('/route/params/actions') -} + function isEqualToModelPathValue(value, modelPath) { + const modelPathValue = getValue(model, modelPath) + // watchDependency('model#' + modelPath) + return modelPathValue === value + } -function showOpsRequestOptions({ model, getValue, watchDependency, storeGet, discriminator }) { - if (isKubedb({ storeGet }) === true) return true - watchDependency('model#/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/databaseRef/name') - watchDependency('discriminator#/autoscalingType') - return ( - !!getValue(model, '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/databaseRef/name') && - !!getValue(discriminator, '/autoscalingType') - ) -} + function onAgentChange() { + const agent = getValue(model, '/resources/kubedbComZooKeeper/spec/monitor/agent') + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/endpoints', + value: [], + force: true, + }) -async function getNamespaces({ axios, storeGet }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + onNamespaceChange() + onLabelChange() + } else { + commit('wizard/model$delete', '/resources/monitoringCoreosComServiceMonitor') + } + } - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + function onLabelChange() { + const labels = getValue(model, '/resources/kubedbComZooKeeper/spec/metadata/labels') - const resources = (resp && resp.data && resp.data.items) || [] + const agent = getValue(model, '/resources/kubedbComZooKeeper/spec/monitor/agent') - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + if (agent === 'prometheus.io') { + commit('wizard/model$update', { + path: '/resources/monitoringCoreosComServiceMonitor/spec/selector/matchLabels', + value: labels, + force: true, + }) } - }) -} + } -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - watchDependency('model#/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/namespace') - const namespace = getValue( - model, - '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/namespace', - ) - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + function getOpsRequestUrl(reqType) { + const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + const owner = storeGet('/route/params/user') + const dbname = getValue(model, '/metadata/release/name') + const group = getValue(model, '/metadata/resource/group') + const kind = getValue(model, '/metadata/resource/kind') + const namespace = getValue(model, '/metadata/release/namespace') + const resource = getValue(model, '/metadata/resource/name') + const version = getValue(model, '/metadata/resource/version') + const routeRootPath = storeGet('/route/path') + const pathPrefix = `${domain}/db${routeRootPath}` + const pathSplit = pathPrefix.split('/').slice(0, -1).join('/') + const pathConstructedForKubedb = + pathSplit + `/create-opsrequest-${reqType.toLowerCase()}?namespace=${namespace}` + + const isKube = !!storeGet('/route/params/actions') + + if (isKube) return pathConstructedForKubedb + else + return `${domain}/console/${owner}/kubernetes/${cluster}/ops.kubedb.com/v1alpha1/zookeeperopsrequests/create?name=${dbname}&namespace=${namespace}&group=${group}&version=${version}&resource=${resource}&kind=${kind}&page=operations&requestType=${reqType}` + } - const resources = (resp && resp.data && resp.data.items) || [] + function onNamespaceChange() { + const namespace = getValue( + model, + '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/namespace', + ) + if (!namespace) { + commit( + 'wizard/model$delete', + '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/databaseRef/name', + ) + } + } - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + function setValueFrom() { + if (isConfigMapTypeValueFrom()) { + return 'configMap' + } else if (isSecretTypeValueFrom()) { + return 'secret' + } else { + return 'input' } - }) -} + } -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isConfigMapTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.configMapKeyRef) + } -async function getDbDetails({ commit, setDiscriminatorValue, axios, storeGet, getValue, model }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = - storeGet('/route/query/namespace') || - getValue(model, '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/namespace') || - '' - const name = - storeGet('/route/params/name') || - getValue(model, '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/databaseRef/name') || - '' - - if (namespace && name) { - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/zookeepers/${name}`, - ) - dbDetails = resp.data || {} - setDiscriminatorValue('/dbDetails', true) - } catch (e) { - console.log(e) + function isSecretTypeValueFrom() { + const valueFrom = getValue(discriminator, '/valueFrom') + return !!(valueFrom && valueFrom.secretKeyRef) + } + + function onValueFromChange() { + const valueFrom = getValue(discriminator, '/valueFromType') + if (valueFrom === 'input') { + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) + } else if (valueFrom === 'secret') { + if (!isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: false, + }) + if (isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: true, + }) + } else if (valueFrom === 'configMap') { + if (!isConfigMapTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/configMapKeyRef', + value: false, + }) + if (isSecretTypeValueFrom()) + commit('wizard/model$update', { + path: 'temp/valueFrom/secretKeyRef', + value: true, + }) } } - commit('wizard/model$update', { - path: `/metadata/release/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/metadata/release/namespace`, - value: namespace, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/databaseRef/name`, - value: name, - force: true, - }) - commit('wizard/model$update', { - path: `/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/labels`, - value: dbDetails.metadata.labels, - force: true, - }) -} + function isEqualToValueFromType(value) { + //watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -function initMetadata({ getValue, discriminator, model, commit, storeGet }) { - const dbName = - getValue(model, '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/databaseRef/name') || - '' - const type = getValue(discriminator, '/autoscalingType') || '' - const date = Math.floor(Date.now() / 1000) - const resource = storeGet('/route/params/resource') - const scalingName = dbName ? dbName : resource - const modifiedName = `${scalingName}-${date}-autoscaling-${type ? type : ''}` - if (modifiedName) - commit('wizard/model$update', { - path: '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/name', - value: modifiedName, - force: true, + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - // delete the other type object from model - if (type === 'compute') - commit('wizard/model$delete', '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/storage') - if (type === 'storage') - commit('wizard/model$delete', '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/compute') -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function onNamespaceChange({ model, getValue, commit }) { - const namespace = getValue( - model, - '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/namespace', - ) - if (!namespace) { - commit( - 'wizard/model$delete', - '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/databaseRef/name', - ) + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) } -} -async function fetchNodeTopology({ axios, storeGet }) { - const owner = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const url = `/clusters/${owner}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies` - try { - const resp = await axios.get(url) - const list = (resp && resp.data?.items) || [] - const mappedList = list.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return name - }) - return mappedList - } catch (e) { - console.log(e) + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } - return [] -} -function isNodeTopologySelected({ watchDependency, model, getValue }) { - watchDependency( - 'model#/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/compute/nodeTopology/name', - ) - const nodeTopologyName = - getValue( + async function getConfigMapKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const configMapName = getValue( model, - '/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/compute/nodeTopology/name', - ) || '' - return !!nodeTopologyName.length -} + '/resources/kubedbComZooKeeper/spec/monitor/prometheus/exporter/env/items/valueFrom/configMapKeyRef/name', + ) -function setControlledResources({ commit }, type) { - const list = ['cpu', 'memory'] - const path = `/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/compute/${type}/controlledResources` - commit('wizard/model$update', { - path: path, - value: list, - force: true, - }) - return list -} + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/configMapKeyRef/name') -function setTrigger({ model, getValue }, path) { - let value = getValue(model, `/resources/${path}`) - if (value) return value - return 'On' -} + if (!configMapName) return [] -function setApplyToIfReady() { - return 'IfReady' -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/configmaps/${configMapName}`, + ) -async function fetchTopologyMachines({ axios, getValue, storeGet, model, setDiscriminatorValue }) { - const instance = hasAnnotations({ model, getValue }) + const configMaps = (resp && resp.data && resp.data.data) || {} - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - if (instance) { - try { - const url = `/clusters/${user}/${cluster}/proxy/node.k8s.appscode.com/v1alpha1/nodetopologies/kubedb-ui-machine-profiles` - const resp = await axios.get(url) + const configMapKeys = Object.keys(configMaps).map((item) => ({ + text: item, + value: item, + })) - const nodeGroups = resp.data?.spec?.nodeGroups || [] - setDiscriminatorValue('/topologyMachines', nodeGroups) - return nodeGroups + return configMapKeys } catch (e) { console.log(e) return [] } } -} -function setAllowedMachine({ model, getValue }, minmax) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] - const mx = instance?.includes(',') ? instance.split(',')[1] : '' - const mn = instance?.includes(',') ? instance.split(',')[0] : '' + async function getSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') - if (minmax === 'min') return mn - else return mx -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -async function getMachines({ getValue, watchDependency, discriminator }, minmax) { - watchDependency('discriminator#/topologyMachines') - const depends = minmax === 'min' ? 'max' : 'min' - const dependantPath = `/allowedMachine-${depends}` + const secrets = (resp && resp.data && resp.data.items) || [] - watchDependency(`discriminator#${dependantPath}`) - const dependantMachine = getValue(discriminator, dependantPath) + const filteredSecrets = secrets.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) - const nodeGroups = getValue(discriminator, '/topologyMachines') || [] + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } catch (e) { + console.log(e) + return [] + } + } - const dependantIndex = nodeGroups?.findIndex((item) => item.topologyValue === dependantMachine) + async function getSecretKeys() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // const namespace = getValue(reusableElementCtx, '/dataContext/namespace') // not supported + const namespace = getValue(model, '/metadata/release/namespace') + const secretName = getValue( + model, + '/resources/kubedbComZooKeeper/spec/monitor/prometheus/exporter/env/items/valueFrom/secretKeyRef/name', + ) - const machines = nodeGroups?.map((item) => { - const subText = `CPU: ${item.allocatable.cpu}, Memory: ${item.allocatable.memory}` - const text = item.topologyValue - return { text, subText, value: item.topologyValue } - }) + // watchDependency('data#/namespace') + // watchDependency('rootModel#/valueFrom/secretKeyRef/name') - const filteredMachine = machines?.filter((item, ind) => - minmax === 'min' ? ind <= dependantIndex : ind >= dependantIndex, - ) + if (!secretName) return [] - return dependantIndex === -1 ? machines : filteredMachine -} + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets/${secretName}`, + ) -function hasAnnotations({ model, getValue }) { - const annotations = getValue( - model, - '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/annotations', - ) - const instance = annotations['kubernetes.io/instance-type'] + const secret = (resp && resp.data && resp.data.data) || {} - return !!instance -} + const secretKeys = Object.keys(secret).map((item) => ({ + text: item, + value: item, + })) -function hasNoAnnotations({ model, getValue }) { - return !hasAnnotations({ model, getValue }) -} + return secretKeys + } catch (e) { + console.log(e) + return [] + } + } -function onMachineChange({ model, getValue, discriminator, commit }, type) { - const annoPath = '/resources/autoscalingKubedbComZooKeeperAutoscaler/metadata/annotations' - const annotations = getValue(model, annoPath) - const instance = annotations['kubernetes.io/instance-type'] + async function getResources(group, version, resource) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const minMachine = getValue(discriminator, '/allowedMachine-min') - const maxMachine = getValue(discriminator, '/allowedMachine-max') - const minMaxMachine = `${minMachine},${maxMachine}` - annotations['kubernetes.io/instance-type'] = minMaxMachine + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const machines = getValue(discriminator, `/topologyMachines`) || [] - const minMachineObj = machines.find((item) => item.topologyValue === minMachine) - const maxMachineObj = machines.find((item) => item.topologyValue === maxMachine) - const minMachineAllocatable = minMachineObj?.allocatable - const maxMachineAllocatable = maxMachineObj?.allocatable - const allowedPath = `/resources/autoscalingKubedbComZooKeeperAutoscaler/spec/compute/${type}` + const resources = (resp && resp.data && resp.data.items) || [] - if (minMachine && maxMachine && instance !== minMaxMachine) { - commit('wizard/model$update', { - path: `${allowedPath}/maxAllowed`, - value: maxMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: `${allowedPath}/minAllowed`, - value: minMachineAllocatable, - force: true, - }) - commit('wizard/model$update', { - path: annoPath, - value: { ...annotations }, - force: true, - }) + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } } -} -return { - getOpsRequestUrl, - onAgentChange, - fetchJsons, - setMetadata, - isEqualToModelPathValue, - isValueExistInModel, - showMonitoringSection, - onEnableMonitoringChange, - showCustomizeExporterSection, - onCustomizeExporterChange, - initBackupData, - isBackupDataLoadedTrue, - setBackupType, - getTypes, - isBackupType, - getContext, - onContextChange, - getConfigList, - onConfigChange, - showPause, - showSchedule, - showConfigList, - setBlueprintSwitch, - onBlueprintChange, - setArchiverSwitch, - onArchiverChange, - onBackupTypeChange, - returnFalse, - onInputChangeSchedule, - getDefaultSchedule, - isConsole, - isKubedb, - showOpsRequestOptions, - getNamespaces, - getDbs, - isRancherManaged, - getDbDetails, - initMetadata, - onNamespaceChange, - fetchNodeTopology, - isNodeTopologySelected, - setControlledResources, - setTrigger, - setApplyToIfReady, - - getMachines, - setAllowedMachine, - hasAnnotations, - hasNoAnnotations, - fetchTopologyMachines, - onMachineChange, + function returnFalse() { + return false + } + + return { + returnFalse, + initScheduleBackup, + initScheduleBackupForEdit, + showBackupForm, + initBackupData, + isBackupDataLoadedTrue, + setBackupType, + getTypes, + onBackupTypeChange, + isBackupType, + setBlueprintSwitch, + onBlueprintChange, + setArchiverSwitch, + onArchiverChange, + getContext, + onContextChange, + getConfigList, + onConfigChange, + showPause, + showConfigList, + showSchedule, + showScheduleBackup, + getDefaultSchedule, + onInputChangeSchedule, + resourceNames, + getNamespacedResourceList, + getConfigMapKeys, + getSecrets, + getSecretKeys, + getResources, + isValueExistInModel, + showMonitoringSection, + onEnableMonitoringChange, + showCustomizeExporterSection, + onCustomizeExporterChange, + isEqualToModelPathValue, + onAgentChange, + onLabelChange, + getOpsRequestUrl, + setValueFrom, + isConfigMapTypeValueFrom, + isSecretTypeValueFrom, + onValueFromChange, + isEqualToValueFromType, + } } diff --git a/charts/opskubedbcom-druidopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-druidopsrequest-editor/ui/create-ui.yaml index b181d30c5b..8c71fb2ee4 100644 --- a/charts/opskubedbcom-druidopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-druidopsrequest-editor/ui/create-ui.yaml @@ -1,672 +1,600 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - discriminator: - machine-middleManagers: - default: "" - type: string - elements: - - computed: setMachine|middleManagers - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|middleManagers|/spec/topology/middleManagers/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-middleManagers - type: select - - if: isMachineCustom|/machine-middleManagers - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/middleManagers/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/middleManagers/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/middleManagers/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/middleManagers/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/middleManagers/properties/topology - show_label: true - type: single-step-form - label: - text: Middle Managers - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/middleManagers - show_label: true - type: single-step-form - - discriminator: - machine-historicals: - default: "" - type: string - elements: - - computed: setMachine|historicals - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|historicals|/spec/topology/historicals/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-historicals - type: select - - if: isMachineCustom|/machine-historicals - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/historicals/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/historicals/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/historicals/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/historicals/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/historicals/properties/topology - show_label: true - type: single-step-form - label: - text: Historicals - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/historicals - show_label: true - type: single-step-form - - discriminator: - machine-brokers: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Expand your database volume + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure TLS for your database + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion elements: - - computed: setMachine|brokers - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|brokers|/spec/topology/brokers/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-brokers - type: select - - if: isMachineCustom|/machine-brokers - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/brokers/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/brokers/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/brokers/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/brokers/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/brokers/properties/topology - show_label: true - type: single-step-form - label: - text: Broker - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/brokers - show_label: true - type: single-step-form - - discriminator: - machine-coordinators: - default: "" - type: string + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - computed: setMachine|coordinators - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|coordinators|/spec/topology/coordinators/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-coordinators - type: select - - if: isMachineCustom|/machine-coordinators - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinators/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinators/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinators/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinators/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinators/properties/topology - show_label: true - type: single-step-form - label: - text: Coordinators - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinators - show_label: true - type: single-step-form - - discriminator: - machine-overlords: - default: "" - type: string + - type: block-layout + label: Middle Managers + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|middleManagers + init: + type: func + value: setMachine|middleManagers + watcher: + func: onMachineChange|middleManagers|/spec/topology/middleManagers/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/middleManagers/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/middleManagers/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/middleManagers/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/middleManagers/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/middleManagers/properties/topology/properties/value + - type: block-layout + label: Historicals + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|historicals + init: + type: func + value: setMachine|historicals + watcher: + func: onMachineChange|historicals|/spec/topology/historicals/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/historicals/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/historicals/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/historicals/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/historicals/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/historicals/properties/topology/properties/value + - type: block-layout + label: Broker + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|brokers + init: + type: func + value: setMachine|brokers + watcher: + func: onMachineChange|brokers|/spec/topology/brokers/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/brokers/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/brokers/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/brokers/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/brokers/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/brokers/properties/topology/properties/value + - type: block-layout + label: Coordinators + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|coordinators + init: + type: func + value: setMachine|coordinators + watcher: + func: onMachineChange|coordinators|/spec/topology/coordinators/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/coordinators/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/coordinators/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/coordinators/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/coordinators/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/coordinators/properties/topology/properties/value + - type: block-layout + label: Overlords + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|overlords + init: + type: func + value: setMachine|overlords + watcher: + func: onMachineChange|overlords|/spec/topology/overlords/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/overlords/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/overlords/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/overlords/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/overlords/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/overlords/properties/topology/properties/value + - type: block-layout + label: Routers + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|routers + init: + type: func + value: setMachine|routers + watcher: + func: onMachineChange|routers|/spec/topology/routers/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/routers/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/routers/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/routers/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/routers/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/routers/properties/topology/properties/value +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion elements: - - computed: setMachine|overlords - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|overlords|/spec/topology/overlords/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-overlords - type: select - - if: isMachineCustom|/machine-overlords - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overlords/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overlords/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overlords/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overlords/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overlords/properties/topology - show_label: true - type: single-step-form - label: - text: Overlords - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overlords - show_label: true - type: single-step-form - - discriminator: - machine-routers: - default: "" - type: string + - type: block-layout + label: Historicals + showLabels: true + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/topology/historicals/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/historicals/storage/resources/requests/storage|/spec/volumeExpansion/historicals + schema: schema/properties/spec/properties/volumeExpansion/properties/historicals + - type: block-layout + label: Middle Managers + showLabels: true + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/topology/middleManagers/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/middleManagers/storage/resources/requests/storage|/spec/volumeExpansion/middleManagers + schema: schema/properties/spec/properties/volumeExpansion/properties/middleManagers + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function elements: - - computed: setMachine|routers - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|routers|/spec/topology/routers/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-routers - type: select - - if: isMachineCustom|/machine-routers - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/routers/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/routers/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/routers/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/routers/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/routers/properties/topology - show_label: true - type: single-step-form - label: - text: Routers - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/routers - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - elements: - - computed: setValueFromDbDetails|/spec/topology/historicals/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/historicals - type: input - validationRuleObject: - func: checkVolume|/spec/topology/historicals/storage/resources/requests/storage|/spec/volumeExpansion/historicals - label: - text: Historicals - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/topology/middleManagers/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/middleManagers - type: input - validationRuleObject: - func: checkVolume|/spec/topology/middleManagers/storage/resources/requests/storage|/spec/volumeExpansion/middleManagers - label: - text: Middle Managers - show_label: true - type: single-step-form - - label: - text: Mode - options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: block-layout + label: Configuration + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + type: function + name: ifRequestTypeEqualsTo|ReconfigureTLS elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: radio + label: TLS Operation + if: + type: function + name: hasTlsField + init: + type: func + value: initTlsOperation + watcher: + func: onTlsOperationChange + paths: + - temp/tlsOperation + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + schema: temp/tlsOperation + - type: switch + label: Remove TLS + if: + type: function + name: returnFalse + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: Rotate Certificates + if: + type: function + name: returnFalse + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + - type: block-layout + if: + type: function + name: showIssuerRefAndCertificates elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + if: + type: function + name: showIssuerRefAndCertificates + init: + type: func + value: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-object-form + label: Organizations + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/subject/properties/organizations + elements: + - type: input + label: organization + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/subject/properties/organizations/items + - type: array-object-form + label: countries + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/subject/properties/countries + elements: + - type: input + label: country + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/subject/properties/countries/items + - type: array-object-form + label: organizational_units + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/subject/properties/organizationalUnits + elements: + - type: input + label: organizational_unit + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/subject/properties/organizationalUnits/items + - type: array-object-form + label: provinces + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/subject/properties/provinces + elements: + - type: input + label: province + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/subject/properties/provinces/items + - type: array-object-form + label: DNS Names + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/dnsNames + elements: + - type: input + label: dns name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/dnsNames/items + - type: array-object-form + label: IP Addresses + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/ipAddresses + elements: + - type: input + label: ip Address + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/ipAddresses/items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-druidopsrequest-editor/ui/functions.js b/charts/opskubedbcom-druidopsrequest-editor/ui/functions.js index 4157aca089..b4ee9fbac9 100644 --- a/charts/opskubedbcom-druidopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-druidopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,1018 +305,1011 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} +let machinesFromPreset = [] -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +export const useFunc = (model) => { + const route = store.state?.route -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + getDbDetails() + showAndInitOpsRequestType() - const resources = (resp && resp.data && resp.data.items) || [] + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/druids`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} + } -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + function returnFalse() { + return false + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/druids/${name}` - const resp = await axios.get(url) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resp.data || {} - } else return {} -} - -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.Druid?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/druidversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/druids`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredDruidDbVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredDruidDbVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/druids/${name}` + const resp = await axios.get(url) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + setDiscriminatorValue('/dbDetails', resp.data || {}) + + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.Druid?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/druidversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredDruidVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredDruidVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (dbType === 'Standalone') return true - else return false - } else return false -} + return selectedType === type + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function asDatabaseOperation(route) { - return !!route.params.actions -} + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType({ + discriminator, + getValue, + }) - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + if (dbType === 'Standalone') return true + else return false + } else return false + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function asDatabaseOperation() { + return !!route.params.actions + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return !ver + } -// machine profile stuffs -let machinesFromPreset = [] -function hasMachine({ getValue, discriminator }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - return !!annotations['kubernetes.io/instance-type'] -} + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } - }) - .filter((val) => !!val) + return value === verd } - return arr -} -function setMachine({ getValue, discriminator, storeGet }, type) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + // machine profile stuffs + function getMachines(type) { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = + dbDetails?.spec?.topology?.[type]?.podTemplate?.spec?.containers?.[0]?.resources?.requests + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } + }) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - const machine = parsedInstance[type] || 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function setMachine(type) { + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = + dbDetails?.spec?.topology?.[type]?.podTemplate?.spec?.containers?.[0]?.resources?.requests + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance[type] || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, `/machine-${type}`) - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - if (selectedMachine === 'custom') delete parsedInstance[type] - else parsedInstance[type] = selectedMachine - annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + const path = `/spec/verticalScaling/${type}/resources` - if (machinesFromPreset.length) - commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, - force: true, - }) + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - if (parsedInstance && Object.keys(parsedInstance).length === 0) - commit('wizard/model$delete', '/metadata/annotations') -} + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + if (selectedMachine === 'custom') delete parsedInstance[type] + else parsedInstance[type] = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) -function isMachineCustom({ watchDependency, getValue, discriminator }, path) { - watchDependency(`discriminator#${path}`) - const machine = getValue(discriminator, `${path}`) - return machine === 'custom' -} + if (parsedInstance && Object.keys(parsedInstance).length === 0) + commit('wizard/model$delete', '/metadata/annotations') + } + + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} - -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + const watchPath = `discriminator#/reconfigurationType` + // watchDependency(watchPath) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: `/spec/configuration/applyConfig`, + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + setDiscriminatorValue('/applyConfig', []) + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') + if (apiGroup) return apiGroup + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/remove') + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, + }) + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/rotateCertificates') } } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} - -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - - return verd -} -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + function isIssuerRefRequired() { + const hasTls = hasTlsField() - return !hasTls -} + return !hasTls + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -// ************************************** Set db details ***************************************** + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + return !dbDetails || !dbName + } - return !dbDetails || !dbName -} + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - const retValue = getValue(discriminator, `/dbDetails${path}`) + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name } - return retValue || undefined -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function setResource({ discriminator, getValue, watchDependency }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0]?.resources -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } -function setApplyToIfReady() { - return 'IfReady' -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + const value = parseFloat(match[1]) + const unit = match[2] - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/druid/topology` + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + return value * units[unit] } -} -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function disableAlias() { + return !!(model && model.alias) } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') - - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - - return value * units[unit] -} - -return { - isRancherManaged, - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + fetchJsons, + returnFalse, + isRancherManaged, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-elasticsearchopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-elasticsearchopsrequest-editor/ui/create-ui.yaml index 9ecebca200..548c813266 100644 --- a/charts/opskubedbcom-elasticsearchopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-elasticsearchopsrequest-editor/ui/create-ui.yaml @@ -1,1203 +1,1110 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|combined|horizontalScaling - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/node - type: input - - elements: - - computed: setValueFromDbDetails|/spec/topology/master/replicas - label: - text: labels.master_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/master - type: input - - computed: setValueFromDbDetails|/spec/topology/data/replicas - label: - text: labels.data_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/data - type: input - - computed: setValueFromDbDetails|/spec/topology/ingest/replicas - label: - text: labels.ingest_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/ingest - type: input - - computed: setValueFromDbDetails|/spec/topology/ml/replicas - if: isAuthPluginEqualTo|X-Pack - label: - text: labels.ml_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/ml - type: input - - computed: setValueFromDbDetails|/spec/topology/transform/replicas - if: isAuthPluginEqualTo|X-Pack - label: - text: labels.transform_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/transform - type: input - - computed: setValueFromDbDetails|/spec/topology/dataCold/replicas - if: isAuthPluginEqualTo|X-Pack - label: - text: labels.data_cold_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/dataCold - type: input - - computed: setValueFromDbDetails|/spec/topology/dataContent/replicas - if: isAuthPluginEqualTo|X-Pack - label: - text: labels.data_content_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/dataContent - type: input - - computed: setValueFromDbDetails|/spec/topology/dataFrozen/replicas - if: isAuthPluginEqualTo|X-Pack - label: - text: labels.data_frozen_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/dataFrozen - type: input - - computed: setValueFromDbDetails|/spec/topology/dataHot/replicas - if: isAuthPluginNotEqualTo|SearchGuard - label: - text: labels.data_hot_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/dataHot - type: input - - computed: setValueFromDbDetails|/spec/topology/dataWarm/replicas - if: isAuthPluginNotEqualTo|SearchGuard - label: - text: labels.data_warm_node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/dataWarm - type: input - if: ifDbTypeEqualsTo|topology|horizontalScaling - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - elements: - - discriminator: - machine-master: - default: "" - type: string - elements: - - computed: setMachine|master - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|master|/spec/topology/master/resources - schema: - $ref: discriminator#/machine-master - type: select - - if: isMachineCustom|/machine-master - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/master/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/master/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-master: - default: "" - type: string - topologyValue-master: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|master - schema: - $ref: discriminator#/topologyKey-master - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|master - schema: - $ref: discriminator#/topologyValue-master - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|master - label: - text: labels.master_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/master - show_label: true - type: single-step-form - - discriminator: - machine-data: - default: "" - type: string - elements: - - computed: setMachine|data - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|data|/spec/topology/data/resources - schema: - $ref: discriminator#/machine-data - type: select - - if: isMachineCustom|/machine-data - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-data: - default: "" - type: string - topologyValue-data: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|data - schema: - $ref: discriminator#/topologyKey-data - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|data - schema: - $ref: discriminator#/topologyValue-data - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|data - label: - text: labels.data_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data - show_label: true - type: single-step-form - - discriminator: - machine-ingest: - default: "" - type: string - elements: - - computed: setMachine|ingest - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|ingest|/spec/topology/ingest/resources - schema: - $ref: discriminator#/machine-ingest - type: select - - if: isMachineCustom|/machine-ingest - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/ingest/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/ingest/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-ingest: - default: "" - type: string - topologyValue-ingest: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|ingest - schema: - $ref: discriminator#/topologyKey-ingest - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|ingest - schema: - $ref: discriminator#/topologyValue-ingest - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|ingest - label: - text: labels.ingest_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/ingest - show_label: true - type: single-step-form - - discriminator: - machine-ml: - default: "" - type: string - elements: - - computed: setMachine|ml - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|ml|/spec/topology/ml/resources - schema: - $ref: discriminator#/machine-ml - type: select - - if: isMachineCustom|/machine-ml - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/ml/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/ml/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-ml: - default: "" - type: string - topologyValue-ml: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Expand database volumes + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure TLS + text: ReconfigureTLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling + elements: + - type: input-compare + label: Replicas + if: + type: function + name: ifDbTypeEqualsTo|Combined|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/node + - type: block-layout + label: Replicas + if: + type: function + name: ifDbTypeEqualsTo|Topology|horizontalScaling + showLabels: true elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|ml - schema: - $ref: discriminator#/topologyKey-ml - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|ml - schema: - $ref: discriminator#/topologyValue-ml - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|ml - label: - text: labels.ml_mode - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/ml - show_label: true - type: single-step-form - - discriminator: - machine-transform: - default: "" - type: string - elements: - - computed: setMachine|transform - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|transform|/spec/topology/transform/resources - schema: - $ref: discriminator#/machine-transform - type: select - - if: isMachineCustom|/machine-transform - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/transform/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/transform/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-transform: - default: "" - type: string - topologyValue-transform: - default: "" - type: string + - type: input-compare + label: Master Node + init: + type: func + value: setValueFromDbDetails|/spec/topology/master/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/master + - type: input-compare + label: Data Node + init: + type: func + value: setValueFromDbDetails|/spec/topology/data/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/data + - type: input-compare + label: Ingest Node + init: + type: func + value: setValueFromDbDetails|/spec/topology/ingest/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/ingest + - type: input-compare + label: ML Node + if: + type: function + name: isAuthPluginEqualTo|X-Pack + init: + type: func + value: setValueFromDbDetails|/spec/topology/ml/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/ml + - type: input-compare + label: Transform Node + if: + type: function + name: isAuthPluginEqualTo|X-Pack + init: + type: func + value: setValueFromDbDetails|/spec/topology/transform/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/transform + - type: input-compare + label: Data Cold Node + if: + type: function + name: isAuthPluginEqualTo|X-Pack + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataCold/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/dataCold + - type: input-compare + label: Data Content Node + if: + type: function + name: isAuthPluginEqualTo|X-Pack + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataContent/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/dataContent + - type: input-compare + label: Data Frozen Node + if: + type: function + name: isAuthPluginEqualTo|X-Pack + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataFrozen/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/dataFrozen + - type: input-compare + label: Data Hot Node + if: + type: function + name: isAuthPluginNotEqualTo|SearchGuard + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataHot/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/dataHot + - type: input-compare + label: Data Warm Node + if: + type: function + name: isAuthPluginNotEqualTo|SearchGuard + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataWarm/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/dataWarm +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: block-layout + if: + type: function + name: ifDbTypeEqualsTo|Topology|verticalScaling + showLabels: false elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|transform - schema: - $ref: discriminator#/topologyKey-transform - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|transform - schema: - $ref: discriminator#/topologyValue-transform - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|transform - label: - text: labels.transform_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/transform - show_label: true - type: single-step-form - - discriminator: - machine-dataCold: - default: "" - type: string - elements: - - computed: setMachine|dataCold - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|dataCold|/spec/topology/dataCold/resources - schema: - $ref: discriminator#/machine-dataCold - type: select - - if: isMachineCustom|/machine-dataCold - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataCold/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataCold/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-dataCold: - default: "" - type: string - topologyValue-dataCold: - default: "" - type: string + - type: block-layout + label: Master Node + showLabels: true + if: + type: function + name: hasResourceValue|master + elements: + - type: machine-compare + label: Resources + loader: getMachines|master + init: + type: func + value: setMachine|master + watcher: + func: onMachineChange|master|/spec/topology/master/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/master/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/master/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/master/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|master + schema: temp/topologyKey-master + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|master + schema: temp/topologyValue-master + - type: block-layout + label: Data Node + showLabels: true + if: + type: function + name: hasResourceValue|data + elements: + - type: machine-compare + label: Resources + loader: getMachines|data + init: + type: func + value: setMachine|data + watcher: + func: onMachineChange|data|/spec/topology/data/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/data/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/data/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/data/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|data + schema: temp/topologyKey-data + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|data + schema: temp/topologyValue-data + - type: block-layout + label: Ingest Node + showLabels: true + if: + type: function + name: hasResourceValue|ingest + elements: + - type: machine-compare + label: Resources + loader: getMachines|ingest + init: + type: func + value: setMachine|ingest + watcher: + func: onMachineChange|ingest|/spec/topology/ingest/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/ingest/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/ingest/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/ingest/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|ingest + schema: temp/topologyKey-ingest + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|ingest + schema: temp/topologyValue-ingest + - type: block-layout + label: ML Node + showLabels: true + if: + type: function + name: hasResourceValue|ml + elements: + - type: machine-compare + label: Resources + loader: getMachines|ml + init: + type: func + value: setMachine|ml + watcher: + func: onMachineChange|ml|/spec/topology/ml/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/ml/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/ml/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/ml/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|ml + schema: temp/topologyKey-ml + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|ml + schema: temp/topologyKey-ml + - type: block-layout + label: Transform Node + showLabels: true + if: + type: function + name: hasResourceValue|transform + elements: + - type: machine-compare + label: Resources + loader: getMachines|transform + init: + type: func + value: setMachine|transform + watcher: + func: onMachineChange|transform|/spec/topology/transform/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/transform/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/transform/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/transform/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|transform + schema: temp/topologyKey-transform + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|transform + schema: temp/topologyValue-transform + - type: block-layout + label: Data Cold Node + showLabels: true + if: + type: function + name: hasResourceValue|dataCold + elements: + - type: machine-compare + label: Resources + loader: getMachines|dataCold + init: + type: func + value: setMachine|dataCold + watcher: + func: onMachineChange|dataCold|/spec/topology/dataCold/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/dataCold/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/dataCold/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/dataCold/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataCold + schema: temp/topologyKey-dataCold + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataCold + schema: temp/topologyValue-dataCold + - type: block-layout + label: Data Content Node + showLabels: true + if: + type: function + name: hasResourceValue|dataContent + elements: + - type: machine-compare + label: Resources + loader: getMachines|dataContent + init: + type: func + value: setMachine|dataContent + watcher: + func: onMachineChange|dataContent|/spec/topology/dataContent/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/dataContent/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/dataContent/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/dataContent/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataContent + schema: temp/topologyKey-dataContent + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataContent + schema: temp/topologyValue-dataContent + - type: block-layout + label: Data Frozen Node + showLabels: true + if: + type: function + name: hasResourceValue|dataFrozen + elements: + - type: machine-compare + label: Resources + loader: getMachines|dataFrozen + init: + type: func + value: setMachine|dataFrozen + watcher: + func: onMachineChange|dataFrozen|/spec/topology/dataFrozen/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/dataFrozen/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/dataFrozen/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/dataFrozen/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataFrozen + schema: temp/topologyKey-dataFrozen + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataFrozen + schema: temp/topologyValue-dataFrozen + - type: block-layout + label: Data Hot Node + showLabels: true + if: + type: function + name: hasResourceValue|dataHot + elements: + - type: machine-compare + label: Resources + loader: getMachines|dataHot + init: + type: func + value: setMachine|dataHot + watcher: + func: onMachineChange|dataHot|/spec/topology/dataHot/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/dataHot/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/dataHot/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/dataHot/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataHot + schema: temp/topologyKey-dataHot + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataHot + schema: temp/topologyValue-dataHot + - type: block-layout + label: Data Warm Node + showLabels: true + if: + type: function + name: hasResourceValue|dataWarm + elements: + - type: machine-compare + label: Resources + loader: getMachines|dataWarm + init: + type: func + value: setMachine|dataWarm + watcher: + func: onMachineChange|dataWarm|/spec/topology/dataWarm/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/dataWarm/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/dataWarm/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/dataWarm/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataWarm + schema: temp/topologyKey-dataWarm + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|dataWarm + schema: temp/topologyValue-dataWarm + - type: block-layout + label: Node + showLabels: true + if: + type: function + name: ifDbTypeEqualsTo|Combined|verticalScaling elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|dataCold - schema: - $ref: discriminator#/topologyKey-dataCold - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|dataCold - schema: - $ref: discriminator#/topologyValue-dataCold - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|dataCold - label: - text: labels.data_cold_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataCold - show_label: true - type: single-step-form - - discriminator: - machine-dataContent: - default: "" - type: string - elements: - - computed: setMachine|dataContent - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|dataContent|/spec/topology/dataContent/resources - schema: - $ref: discriminator#/machine-dataContent - type: select - - if: isMachineCustom|/machine-dataContent - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataContent/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataContent/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-dataContent: - default: "" - type: string - topologyValue-dataContent: - default: "" - type: string + - type: machine-compare + label: Resources + loader: getMachines|node + init: + type: func + value: setMachine|node + watcher: + func: onMachineChange|node|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|node + schema: temp/topologyKey-node + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|node + schema: temp/topologyValue-node + - type: horizontal-layout + showLabels: true + label: Exporter elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|dataContent - schema: - $ref: discriminator#/topologyKey-dataContent - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|dataContent - schema: - $ref: discriminator#/topologyValue-dataContent - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|dataContent - label: - text: labels.data_content_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataCold - show_label: true - type: single-step-form - - discriminator: - machine-dataFrozen: - default: "" - type: string - elements: - - computed: setMachine|dataFrozen - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|dataFrozen|/spec/topology/dataFrozen/resources - schema: - $ref: discriminator#/machine-dataFrozen - type: select - - if: isMachineCustom|/machine-dataFrozen - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataFrozen/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/cpu|/spec/verticalScaling/exporter/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/cpu|/spec/verticalScaling/exporter/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/memory|/spec/verticalScaling/exporter/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/memory|/spec/verticalScaling/exporter/resources/limits/memory +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion + elements: + - type: input-compare + label: Storage Size + if: + type: function + name: ifDbTypeEqualsTo|Combined|VolumeExpansion + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node + schema: schema/properties/spec/properties/volumeExpansion/properties/node + - type: select + label: Mode + validation: + type: required options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataFrozen/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-dataFrozen: - default: "" - type: string - topologyValue-dataFrozen: - default: "" - type: string + - text: Offline + value: Offline + - text: Online + value: Online + schema: schema/properties/spec/properties/volumeExpansion/properties/mode + - type: block-layout + label: Storage Size + if: + type: function + name: ifDbTypeEqualsTo|Topology|VolumeExpansion + showLabels: true elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|dataFrozen - schema: - $ref: discriminator#/topologyKey-dataFrozen - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|dataFrozen - schema: - $ref: discriminator#/topologyValue-dataFrozen - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|dataFrozen - label: - text: labels.data_frozen_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataFrozen - show_label: true - type: single-step-form - - discriminator: - machine-dataHot: - default: "" - type: string - elements: - - computed: setMachine|dataHot - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|dataHot|/spec/topology/dataHot/resources - schema: - $ref: discriminator#/machine-dataHot - type: select - - if: isMachineCustom|/machine-dataHot - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataHot/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataHot/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-dataHot: - default: "" - type: string - topologyValue-dataHot: - default: "" - type: string + - type: input-compare + label: Master Size + if: + type: function + name: hasVolumeExpansion|master + init: + type: func + value: setValueFromDbDetails|/spec/topology/master/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/master/storage/resources/requests/storage|/spec/volumeExpansion/master + schema: schema/properties/spec/properties/volumeExpansion/properties/master + - type: input-compare + label: Data Size + if: + type: function + name: hasVolumeExpansion|data + init: + type: func + value: setValueFromDbDetails|/spec/topology/data/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/data/storage/resources/requests/storage|/spec/volumeExpansion/data + schema: schema/properties/spec/properties/volumeExpansion/properties/data + - type: input-compare + label: Ingest Size + if: + type: function + name: hasVolumeExpansion|ingest + init: + type: func + value: setValueFromDbDetails|/spec/topology/ingest/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/ingest/storage/resources/requests/storage|/spec/volumeExpansion/ingest + schema: schema/properties/spec/properties/volumeExpansion/properties/ingest + - type: input-compare + label: ML Size + if: + type: function + name: hasVolumeExpansion|ml + init: + type: func + value: setValueFromDbDetails|/spec/topology/ml/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/ml/storage/resources/requests/storage|/spec/volumeExpansion/ml + schema: schema/properties/spec/properties/volumeExpansion/properties/ml + - type: input-compare + label: Transform Size + if: + type: function + name: hasVolumeExpansion|transform + init: + type: func + value: setValueFromDbDetails|/spec/topology/transform/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/transform/storage/resources/requests/storage|/spec/volumeExpansion/transform + schema: schema/properties/spec/properties/volumeExpansion/properties/transform + - type: input-compare + label: Data Cold Size + if: + type: function + name: hasVolumeExpansion|dataCold + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataCold/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/dataCold/storage/resources/requests/storage|/spec/volumeExpansion/dataCold + schema: schema/properties/spec/properties/volumeExpansion/properties/dataCold + - type: input-compare + label: Data Content Size + if: + type: function + name: hasVolumeExpansion|dataContent + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataContent/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/dataContent/storage/resources/requests/storage|/spec/volumeExpansion/dataContent + schema: schema/properties/spec/properties/volumeExpansion/properties/dataContent + - type: input-compare + label: Data Frozen Size + if: + type: function + name: hasVolumeExpansion|dataFrozen + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataFrozen/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/dataFrozen/storage/resources/requests/storage|/spec/volumeExpansion/dataFrozen + schema: schema/properties/spec/properties/volumeExpansion/properties/dataFrozen + - type: input-compare + label: Data Hot Size + if: + type: function + name: hasVolumeExpansion|dataHot + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataHot/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/dataHot/storage/resources/requests/storage|/spec/volumeExpansion/dataHot + schema: schema/properties/spec/properties/volumeExpansion/properties/dataHot + - type: input-compare + label: Data Warm Size + if: + type: function + name: hasVolumeExpansion|dataWarm + init: + type: func + value: setValueFromDbDetails|/spec/topology/dataWarm/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/dataWarm/storage/resources/requests/storage|/spec/volumeExpansion/dataWarm + schema: schema/properties/spec/properties/volumeExpansion/properties/dataWarm + # Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|dataHot - schema: - $ref: discriminator#/topologyKey-dataHot - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|dataHot - schema: - $ref: discriminator#/topologyValue-dataHot - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|dataHot - label: - text: labels.dataHot_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataHot - show_label: true - type: single-step-form - - discriminator: - machine-dataWarm: - default: "" - type: string - elements: - - computed: setMachine|dataWarm - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|dataWarm|/spec/topology/dataWarm/resources - schema: - $ref: discriminator#/machine-dataWarm - type: select - - if: isMachineCustom|/machine-dataWarm - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataWarm/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function + +# Reconfigure TLS + - type: block-layout + label: TLS + if: + type: function + name: ifRequestTypeEqualsTo|ReconfigureTLS + elements: + - type: radio + label: TLS Operation + if: + type: function + name: hasTlsField + init: + type: func + value: initTlsOperation options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataWarm/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-dataWarm: - default: "" - type: string - topologyValue-dataWarm: - default: "" - type: string + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + watcher: + func: onTlsOperationChange + paths: + - temp/tlsOperation + schema: temp/tlsOperation + - type: switch + label: '' + if: + type: function + name: returnFalse + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: '' + if: + type: function + name: returnFalse + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + - type: block-layout + label: Issuer Ref + if: + type: function + name: showIssuerRefAndCertificates + showLabels: false elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|dataWarm - schema: - $ref: discriminator#/topologyKey-dataWarm - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|dataWarm - schema: - $ref: discriminator#/topologyValue-dataWarm - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: hasResourceValue|dataWarm - label: - text: labels.data_warm_node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/dataWarm - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|topology|verticalScaling - schema: - $ref: schema#/properties/spec/properties/verticalScaling - type: single-step-form - - discriminator: - machine-node: - default: "" - type: string - elements: - - computed: setMachine|node - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|node|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine-node - type: select - - if: isMachineCustom|/machine-node - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-node: - default: "" - type: string - topologyValue-node: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|node - schema: - $ref: discriminator#/topologyKey-node - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|node - schema: - $ref: discriminator#/topologyValue-node - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|combined|verticalScaling - label: - text: labels.node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node - show_label: true - type: single-step-form - - computed: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources|/spec/verticalScaling/exporter/resources - label: - text: labels.exporter - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter/properties/resources - type: resource-input-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - if: ifDbTypeEqualsTo|combined|VolumeExpansion - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/node - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node - - label: - text: Mode - options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - - elements: - - computed: setValueFromDbDetails|/spec/topology/master/storage/resources/requests/storage - if: hasVolumeExpansion|master - label: - text: labels.storage.master_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/master - type: input - validationRuleObject: - func: checkVolume|/spec/topology/master/storage/resources/requests/storage|/spec/volumeExpansion/master - - computed: setValueFromDbDetails|/spec/topology/data/storage/resources/requests/storage - if: hasVolumeExpansion|data - label: - text: labels.storage.data_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/data - type: input - validationRuleObject: - func: checkVolume|/spec/topology/data/storage/resources/requests/storage|/spec/volumeExpansion/data - - computed: setValueFromDbDetails|/spec/topology/ingest/storage/resources/requests/storage - if: hasVolumeExpansion|ingest - label: - text: labels.storage.ingest_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/ingest - type: input - validationRuleObject: - func: checkVolume|/spec/topology/ingest/storage/resources/requests/storage|/spec/volumeExpansion/ingest - - computed: setValueFromDbDetails|/spec/topology/ml/storage/resources/requests/storage - if: hasVolumeExpansion|ml - label: - text: labels.storage.ml_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/ml - type: input - validationRuleObject: - func: checkVolume|/spec/topology/ml/storage/resources/requests/storage|/spec/volumeExpansion/ml - - computed: setValueFromDbDetails|/spec/topology/transform/storage/resources/requests/storage - if: hasVolumeExpansion|transform - label: - text: labels.storage.transform_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/transform - type: input - validationRuleObject: - func: checkVolume|/spec/topology/transform/storage/resources/requests/storage|/spec/volumeExpansion/transform - - computed: setValueFromDbDetails|/spec/topology/dataCold/storage/resources/requests/storage - if: hasVolumeExpansion|dataCold - label: - text: labels.storage.data_cold_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/dataCold - type: input - validationRuleObject: - func: checkVolume|/spec/topology/dataCold/storage/resources/requests/storage|/spec/volumeExpansion/dataCold - - computed: setValueFromDbDetails|/spec/topology/dataContent/storage/resources/requests/storage - if: hasVolumeExpansion|dataContent - label: - text: labels.storage.data_content_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/dataContent - type: input - validationRuleObject: - func: checkVolume|/spec/topology/dataContent/storage/resources/requests/storage|/spec/volumeExpansion/dataContent - - computed: setValueFromDbDetails|/spec/topology/dataFrozen/storage/resources/requests/storage - if: hasVolumeExpansion|dataFrozen - label: - text: labels.storage.data_frozen_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/dataFrozen - type: input - validationRuleObject: - func: checkVolume|/spec/topology/dataFrozen/storage/resources/requests/storage|/spec/volumeExpansion/dataFrozen - - computed: setValueFromDbDetails|/spec/topology/dataHot/storage/resources/requests/storage - if: hasVolumeExpansion|dataHot - label: - text: labels.storage.data_hot_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/dataHot - type: input - validationRuleObject: - func: checkVolume|/spec/topology/dataHot/storage/resources/requests/storage|/spec/volumeExpansion/dataHot - - computed: setValueFromDbDetails|/spec/topology/dataWarm/storage/resources/requests/storage - if: hasVolumeExpansion|dataWarm - label: - text: labels.storage.data_warm_size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/dataWarm - type: input - validationRuleObject: - func: checkVolume|/spec/topology/dataWarm/storage/resources/requests/storage|/spec/volumeExpansion/dataWarm - if: ifDbTypeEqualsTo|topology|VolumeExpansion - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string - elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + disable: returnTrue + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + if: + type: function + name: showIssuerRefAndCertificates + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-object-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + elements: + - type: input + label: organization + schema: schema/items/properties/subject/properties/organizations/items + - type: array-object-form + label: Countries + schema: schema/items/properties/subject/properties/countries + elements: + - type: input + label: country + schema: schema/items/properties/subject/properties/countries/items + - type: array-object-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + elements: + - type: input + label: organizational_unit + schema: schema/items/properties/subject/properties/organizationalUnits/items + - type: array-object-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + elements: + - type: input + label: province + schema: schema/items/properties/subject/properties/provinces/items + - type: array-object-form + label: DNS Names + schema: schema/items/properties/dnsNames + elements: + - type: input + label: dns name + schema: schema/items/properties/dnsNames/items + - type: array-object-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + elements: + - type: input + label: ip address + schema: schema/items/properties/ipAddresses/items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-elasticsearchopsrequest-editor/ui/functions.js b/charts/opskubedbcom-elasticsearchopsrequest-editor/ui/functions.js index b5e17ba8ab..dceb605ea9 100644 --- a/charts/opskubedbcom-elasticsearchopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-elasticsearchopsrequest-editor/ui/functions.js @@ -1,3 +1,5 @@ +const { axios, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -304,1078 +306,964 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart +let elasticVersions = [] +let machinesFromPreset = [] +let getAliasOptions = null - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } +export const useFunc = (model) => { + const route = store.state?.route + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} + getDbDetails() + showAndInitOpsRequestType() -function returnFalse() { - return false -} + async function getDbs() { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + if (storeGet('/route/params/actions')) return [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/elasticsearches`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) - const resources = (resp && resp.data && resp.data.items) || [] + const resources = (resp && resp.data && resp.data.items) || [] - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] } - }) -} + } -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/elasticsearches/${name}` - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/elasticsearches`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) + try { + const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + const { version } = resp?.data?.spec || {} + const selectedVersion = elasticVersions?.find((item) => item?.metadata?.name === version) - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + if (resp?.data?.spec) { + resp.data.spec.authPlugin = selectedVersion?.spec?.authPlugin || '' + } -let elasticVersions = [] + setDiscriminatorValue('/dbDetails', resp.data || {}) -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + return resp.data || {} + } catch (e) { + console.log(e) + return {} + } + } else return {} + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/elasticsearches/${name}` - const resp = await axios.get(url) + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const { version } = resp?.data?.spec || {} - const selectedVersion = elasticVersions?.find((item) => item?.metadata?.name === version) + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` - if (resp?.data?.spec) { - resp.data.spec.authPlugin = selectedVersion?.spec?.authPlugin || '' + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } } - setDiscriminatorValue('/dbDetails', resp.data || {}) + try { + const presetVersions = presets.admin?.databases?.Elasticsearch?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } - return resp.data || {} - } else return {} -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/elasticsearchversions`, + { + params: queryParams, + }, + ) -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resources = (resp && resp.data && resp.data.items) || [] - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredElasticsearchVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + return filteredElasticsearchVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - try { - const presetVersions = presets.admin?.databases?.Elasticsearch?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/elasticsearchversions`, - { - params: queryParams, - }, - ) + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - const resources = (resp && resp.data && resp.data.items) || [] - - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredElasticsearchVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 - return filteredElasticsearchVersions.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' - return { - text: `${name} (${specVersion})`, - value: name, - } - }) - } catch (e) { - console.log(e) - return [] + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) - - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 - - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true } - return 0 // versions are equal -} - -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + function getRequestTypeFromRoute() { + if (route.params?.actions) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match?.[2] + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + return opMap[opstype] || '' + } + return '' } - return true -} - -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') - return selectedType === type -} - -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') - - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match?.[2] + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } + return !ver } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} - -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + function asDatabaseOperation() { + return !!route.params.actions } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function generateOpsRequestNameForClusterUI() { + const dbName = getValue(model, '/spec/databaseRef/name') -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const { spec } = dbDetails || {} - return (spec && spec.tls) || undefined -} + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - - const { spec } = dbDetails || {} - const { topology } = spec || {} - let verd = '' - if (topology) { - verd = 'topology' - } else { - verd = 'combined' + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return verd -} - -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' -function clearOpsReqSpec(verd, opsReqType, commit) { - if ( - opsReqType === 'verticalScaling' || - opsReqType === 'horizontalScaling' || - opsReqType === 'volumeExpansion' || - opsReqType === 'configuration' - ) { - if (verd === 'combined') { - commit('wizard/model$delete', `/spec/${opsReqType}/topology`) + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) } else { - commit('wizard/model$delete', `/spec/${opsReqType}/node`) + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(), + force: true, + }) } + return !ver } -} -function asDatabaseOperation(route) { - return !!route.params.actions -} - -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + return !ver + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + return !ver + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + return !dbDetails || !dbName } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, + + function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + + const namespaces = storeGet('/cluster/namespaces') || [] + return namespaces.map((item) => { + return { + text: item, + value: item, + } }) } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace } - return !ver -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(value) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - clearOpsReqSpec(verd, opsReqType, commit) - return value === verd -} + return selectedType === value + } -// machine profile stuffs -let machinesFromPreset = [] -function hasMachine({ getValue, discriminator }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - return !!annotations['kubernetes.io/instance-type'] -} + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + // watchDependency('discriminator#/reconfigurationType') -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } - }) - .filter((val) => !!val) + return reconfigurationType === value } - return arr -} -function setMachine({ getValue, discriminator, storeGet }, type) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) + + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/inlineConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } } - const machine = parsedInstance[type] || 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, `/machine-${type}`) - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } - } + const secrets = (resp && resp.data && resp.data.items) || [] - const path = `/spec/verticalScaling/${type}/resources` + const filteredSecrets = secrets - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + return filteredSecrets } - if (selectedMachine === 'custom') delete parsedInstance[type] - else parsedInstance[type] = selectedMachine - annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) - if (machinesFromPreset.length) + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') + + const configObj = {} + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } + commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) + } - if (parsedInstance && Object.keys(parsedInstance).length === 0) - commit('wizard/model$delete', '/metadata/annotations') -} + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function isMachineCustom({ watchDependency, getValue, discriminator }, path) { - watchDependency(`discriminator#${path}`) - const machine = getValue(discriminator, `${path}`) - return machine === 'custom' -} + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } + } -function isAuthPluginNotEqualTo({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function setValueFromDbDetails(path, commitPath) { + // watchDependency('discriminator#/dbDetails') + const retValue = getValue(discriminator, `/dbDetails${path}`) - const authPlugin = dbDetails?.spec?.authPlugin || '' + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') - return authPlugin && authPlugin !== value -} + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined -function isAuthPluginEqualTo({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + // direct model update required for reusable element. + // computed property is not applicable for reusable element + if (retValue) { + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + } - const authPlugin = dbDetails?.spec?.authPlugin || '' + return retValue || undefined + } - return authPlugin === value -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + const { spec } = dbDetails || {} + const { topology } = spec || {} + let verd = '' + if (topology) { + verd = 'Topology' + } else { + verd = 'Combined' + } - const secrets = (resp && resp.data && resp.data.items) || [] + return verd + } - const filteredSecrets = secrets + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + clearOpsReqSpec(verd, opsReqType) + return value === verd + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function clearOpsReqSpec(verd, opsReqType) { + if ( + opsReqType === 'verticalScaling' || + opsReqType === 'horizontalScaling' || + opsReqType === 'VolumeExpansion' || + opsReqType === 'configuration' + ) { + if (verd === 'Combined') { + commit('wizard/model$delete', `/spec/${opsReqType}/topology`) + } else { + commit('wizard/model$delete', `/spec/${opsReqType}/node`) + } + } + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + function isAuthPluginNotEqualTo(value) { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const authPlugin = dbDetails?.spec?.authPlugin || '' - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return authPlugin && authPlugin !== value } - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function isAuthPluginEqualTo(value) { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + const authPlugin = dbDetails?.spec?.authPlugin || '' - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) - - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return authPlugin === value } - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function hasResourceValue(node) { + // watchDependency('discriminator#/dbDetails') + const nodeResource = getValue(discriminator, `/dbDetails/spec/topology/${node}/resources`) + return !!nodeResource } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + function getMachines(type) { + console.log({ type }) + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = (type && type !== 'node' + ? dbDetails?.spec?.topology?.[type]?.resources?.requests + : dbDetails?.spec?.podTemplate?.spec?.resources?.requests) || { + cpu: '', + memory: '', } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } + }) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) } - }) -} - -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - - return reconfigurationType === value -} -function onReconfigurationTypeChange({ commit, discriminator, getValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) - - commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, - force: true, - }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/inlineConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + return arr } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function setMachine(type) { + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = (type && type !== 'node' + ? dbDetails?.spec?.topology?.[type]?.resources?.requests + : dbDetails?.spec?.podTemplate?.spec?.resources?.requests) || { + cpu: '', + memory: '', + } + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance[type] || 'custom' - return !!tls -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } + } - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + function isVerticalScaleTopologyRequired(type) { + // watchDependency(`discriminator#/topologyKey-${type}`) + // watchDependency(`discriminator#/topologyValue-${type}`) -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const key = getValue(discriminator, `/topologyKey-${type}`) + const value = getValue(discriminator, `/topologyValue-${type}`) + const path = `/spec/verticalScaling/${type}/topology` - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } - } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return { isInvalid: false } + } else { + commit('wizard/model$delete', path) + return { isInvalid: false } } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } + function hasVolumeExpansion(node) { + // watchDependency('discriminator#/dbDetails') + const nodeStorage = getValue( + discriminator, + `/dbDetails/spec/topology/${node}/storage/resources/requests/storage`, + ) + return !!nodeStorage } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) - commit('wizard/model$delete', '/spec/tls') + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + if (inputSizeInBytes >= sizeInBytes) return + else return { isInvalid: true, message: 'Cannot expand to lower volume!' } + } catch (err) { + return { isInvalid: true, message: err.message || 'Invalid' } + } } -} -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - return verd -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + const value = parseFloat(match[1]) + const unit = match[2] - return !hasTls -} + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') -// ************************************** Set db details ***************************************** + return value * units[unit] + } -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + function hasTlsField() { + const tls = getDbTls() + return !!tls + } - return !dbDetails || !dbName -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') - const retValue = getValue(discriminator, `/dbDetails${path}`) + const { spec } = dbDetails || {} + return (spec && spec.tls) || undefined + } + + function initTlsOperation() { + return 'update' + } - if (commitPath) { + function onTlsOperationChange() { const tlsOperation = getValue(discriminator, '/tlsOperation') - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + commit('wizard/model$delete', '/spec/tls') - // direct model update required for reusable element. - // computed property is not applicable for reusable element - if (retValue) { + if (tlsOperation === 'rotate') { commit('wizard/model$update', { - path: commitPath, - value: retValue, + path: '/spec/tls/rotateCertificates', + value: true, force: true, }) + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/remove') + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, + }) + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/rotateCertificates') } } - return retValue || undefined -} + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - if (itemCtx.value === 'ReconfigureTLS') { - const dbDetails = getValue(discriminator, '/dbDetails') - const { issuerRef } = dbDetails?.spec?.tls || {} - return !issuerRef + return verd } - return false -} -function hasResourceValue({ discriminator, getValue, watchDependency }, node) { - watchDependency('discriminator#/dbDetails') - const nodeResource = getValue(discriminator, `/dbDetails/spec/topology/${node}/resources`) - return !!nodeResource -} + function returnTrue() { + return true + } -function hasVolumeExpansion({ discriminator, getValue, watchDependency }, node) { - watchDependency('discriminator#/dbDetails') - const nodeStorage = getValue( - discriminator, - `/dbDetails/spec/topology/${node}/storage/resources/requests/storage`, - ) - return !!nodeStorage -} + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') + + if (kind) { + const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') + if (apiGroup) return apiGroup + return 'cert-manager.io' + } else return undefined + } -function getAliasOptions({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } - const enableSSL = getValue(discriminator, '/dbDetails/spec/enableSSL') - const authPlugin = getValue(discriminator, '/dbDetails/spec/authPlugin') - const monitor = getValue(discriminator, '/dbDetails/spec/monitor') + async function getIssuer(url) { + try { + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } + } - // always include transport cert alias - const aliases = ['transport'] + function isIssuerRefRequired() { + const hasTls = hasTlsField() + return !hasTls + } - if (authPlugin !== 'X-Pack') { - aliases.push('admin') + // Certificate functions + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] } - if (enableSSL) { - aliases.push('http') - aliases.push('archiver') - if (monitor) { - aliases.push('metrics-exporter') + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } } + return {} } - return aliases -} + function disableAlias() { + return !!(model && model.alias) + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + getAliasOptions = () => { + // watchDependency('discriminator#/dbDetails') -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + const enableSSL = getValue(discriminator, '/dbDetails/spec/enableSSL') + const authPlugin = getValue(discriminator, '/dbDetails/spec/authPlugin') + const monitor = getValue(discriminator, '/dbDetails/spec/monitor') -function onNamespaceChange({ commit, route }) { - const { operation } = route.query - // if operation query parameter is present - // then the type is set by showAndInitOpsRequestType and can not be changed or deleted - // otherwise delete the type - if (!operation) { - // delete type - commit('wizard/model$delete', '/spec/type') - } -} + // always include transport cert alias + const aliases = ['transport'] -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - // delete type - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + if (authPlugin !== 'X-Pack') { + aliases.push('admin') + } -function setApplyToIfReady() { - return 'IfReady' -} + if (enableSSL) { + aliases.push('http') + aliases.push('archiver') + if (monitor) { + aliases.push('metrics-exporter') + } + } -function isVerticalScaleTopologyRequired( - { watchDependency, getValue, discriminator, commit }, - type, -) { - watchDependency(`discriminator#/topologyKey-${type}`) - watchDependency(`discriminator#/topologyValue-${type}`) + return aliases + } - const key = getValue(discriminator, `/topologyKey-${type}`) - const value = getValue(discriminator, `/topologyValue-${type}`) - const path = `/spec/verticalScaling/${type}/topology` + function setApplyToIfReady() { + return 'IfReady' + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) + function returnFalse() { return false } -} -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine-${type}`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' - } -} + const path = `/spec/verticalScaling/${type}/resources` -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, - } - - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - const value = parseFloat(match[1]) - const unit = match[2] + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + if (selectedMachine === 'custom') delete parsedInstance[type] + else parsedInstance[type] = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) - return value * units[unit] -} + if (parsedInstance && Object.keys(parsedInstance).length === 0) + commit('wizard/model$delete', '/metadata/annotations') + } -return { - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - clearOpsReqSpec, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - isAuthPluginEqualTo, - isAuthPluginNotEqualTo, - getConfigSecrets, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onApplyconfigChange, - onReconfigurationTypeChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - isDbDetailsLoading, - setValueFromDbDetails, - disableOpsRequest, - hasResourceValue, - hasVolumeExpansion, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + getDbTls, + getDbType, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + isAuthPluginEqualTo, + isAuthPluginNotEqualTo, + isDbDetailsLoading, + setValueFromDbDetails, + hasResourceValue, + hasVolumeExpansion, + isNamespaceDisabled, + isDatabaseRefDisabled, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + checkVolume, + getRequestTypeFromRoute, + hasTlsField, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + returnTrue, + initIssuerRefApiGroup, + getIssuerRefsName, + isIssuerRefRequired, + fetchAliasOptions, + validateNewCertificates, + disableAlias, + onMachineChange, + onReconfigurationTypeChange, + ifReconfigurationTypeEqualsTo, + getConfigSecrets, + onApplyconfigChange, + createSecretUrl, + } } diff --git a/charts/opskubedbcom-ferretdbopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-ferretdbopsrequest-editor/ui/create-ui.yaml index a6596d2bcc..faa9b0ee19 100644 --- a/charts/opskubedbcom-ferretdbopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-ferretdbopsrequest-editor/ui/create-ui.yaml @@ -1,330 +1,373 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/server/primary/replicas - label: - text: Primary Replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/primary/properties/replicas - type: input - - computed: setValueFromDbDetails|/spec/server/secondary/replicas - if: ferretTypeEqualsTo|secondary - label: - text: Secondary Replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/secondary/properties/replicas - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine-primary: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - computed: setMachine|primary - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|primary|/spec/server/primary/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-primary - type: select - - if: isMachineCustom|/machine-primary - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/primary/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/primary/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/primary/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/primary/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/primary/properties/topology - show_label: true - type: single-step-form - label: - text: Primary - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/primary - show_label: true - type: single-step-form - - discriminator: - machine-secondary: - default: "" - type: string + - type: input-compare + label: Primary Replicas + init: + type: func + value: setValueFromDbDetails|/spec/server/primary/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/primary/properties/replicas + - type: input-compare + label: Secondary Replicas + if: + type: function + name: ferretTypeEqualsTo|secondary + init: + type: func + value: setValueFromDbDetails|/spec/server/secondary/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/secondary/properties/replicas +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - computed: setMachine|secondary - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|secondary|/spec/server/secondary/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-secondary - type: select - - if: isMachineCustom|/machine-secondary - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/secondary/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/secondary/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/secondary/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/secondary/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/secondary/properties/topology - show_label: true - type: single-step-form - if: ferretTypeEqualsTo|secondary - label: - text: Secondary - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/secondary - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: block-layout + label: Primary + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|primary + init: + type: func + value: setMachine|primary + watcher: + func: onMachineChange|primary|/spec/server/primary/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/primary/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/primary/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/primary/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|primary + schema: temp/topologyKey-primary + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|primary + schema: temp/topologyValue-primary + - type: block-layout + label: Secondary + showLabels: true + if: + type: function + name: ferretTypeEqualsTo|secondary + elements: + - type: machine-compare + label: Resources + loader: getMachines|secondary + init: + type: func + value: setMachine|secondary + watcher: + func: onMachineChange|secondary|/spec/server/secondary/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/secondary/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/secondary/properties/resources + - type: select + label: Node Selection Policy + schema: schema/properties/spec/properties/verticalScaling/properties/secondary/properties/nodeSelectionPolicy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|secondary + schema: temp/topologyKey-secondary + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|secondary + schema: temp/topologyValue-secondary +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-ferretdbopsrequest-editor/ui/functions.js b/charts/opskubedbcom-ferretdbopsrequest-editor/ui/functions.js index 69aa692fe3..b5414da8ec 100644 --- a/charts/opskubedbcom-ferretdbopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-ferretdbopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,929 +305,941 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/ferretdbs`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} + } -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + function returnFalse() { + return false + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/ferretdbs/${name}` - const resp = await axios.get(url) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resp.data || {} - } else return {} -} - -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.FerretDB?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/ferretdbversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/ferretdbs`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredFerretDBVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredFerretDBVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/ferretdbs/${name}` + const resp = await axios.get(url) - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + setDiscriminatorValue('/dbDetails', resp.data || {}) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.FerretDB?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/ferretdbversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredFerretDBVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredFerretDBVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') + + return selectedType === type + } + + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } + + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) }) + } - if (dbType === 'Standalone') return true - else return false - } else return false -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + return spec?.tls || undefined + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType({ + discriminator, + getValue, + }) -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + if (dbType === 'Standalone') return true + else return false + } else return false + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function asDatabaseOperation() { + return !!route.params.actions + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } + + return !ver } - return !ver -} + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return value === verd + } -// machine profile stuffs -let machinesFromPreset = [] + function ferretTypeEqualsTo(param) { + const dbDetails = getValue(discriminator, '/dbDetails') + const type = dbDetails.spec?.server?.secondary ? 'secondary' : 'primary' + return param === type + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // machine profile stuffs + // let machinesFromPreset = [] + + function getMachines(type) { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = + dbDetails?.spec?.server?.[type]?.podTemplate?.spec?.containers?.[0]?.resources?.requests + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }, type) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - const machine = parsedInstance[type] || 'custom' + function setMachine(type) { + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = + dbDetails?.spec?.server?.[type]?.podTemplate?.spec?.containers?.[0]?.resources?.requests - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance[type] || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, `/machine-${type}`) - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine-${type}`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - if (selectedMachine === 'custom') delete parsedInstance[type] - else parsedInstance[type] = selectedMachine - annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) - - if (machinesFromPreset.length) - commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, - force: true, - }) + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - if (parsedInstance && Object.keys(parsedInstance).length === 0) - commit('wizard/model$delete', '/metadata/annotations') -} + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + if (selectedMachine === 'custom') delete parsedInstance[type] + else parsedInstance[type] = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) -function isMachineCustom({ watchDependency, getValue, discriminator }, path) { - watchDependency(`discriminator#${path}`) - const machine = getValue(discriminator, `${path}`) - return machine === 'custom' -} + if (parsedInstance && Object.keys(parsedInstance).length === 0) + commit('wizard/model$delete', '/metadata/annotations') + } -function ferretTypeEqualsTo({ getValue, discriminator }, param) { - const dbDetails = getValue(discriminator, '/dbDetails') - const type = dbDetails.spec?.server?.secondary ? 'secondary' : 'primary' - return param === type -} + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } + + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, + }) - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + // for tls + function hasTlsField() { + const tls = getDbTls() -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + return !!tls + } - return !!tls -} + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + if (kind) { + return 'cert-manager.io' + } else return undefined + } - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} - -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} - -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - return verd -} - -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) - - return !hasTls -} + function isIssuerRefRequired() { + const hasTls = hasTlsField() -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + return !hasTls + } -// ************************************** Set db details ***************************************** + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') - return !dbDetails || !dbName -} + return !dbDetails || !dbName + } -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) - const retValue = getValue(discriminator, `/dbDetails${path}`) + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace } - return retValue || undefined -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -function setResource({ discriminator, getValue, watchDependency }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0].resources -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function setApplyToIfReady() { + return 'IfReady' + } -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + function isVerticalScaleTopologyRequired(type) { + // watchDependency(`discriminator#/topologyKey-${type}`) + // watchDependency(`discriminator#/topologyValue-${type}`) -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + const key = getValue(discriminator, `/topologyKey-${type}`) + const value = getValue(discriminator, `/topologyValue-${type}`) + const path = `/spec/verticalScaling/${type}/topology` -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } + } -function setApplyToIfReady() { - return 'IfReady' -} + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/ferretdb/topology` + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + function disableAlias() { + return !!(model && model.alias) } -} -return { - isRancherManaged, - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - ferretTypeEqualsTo, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + ferretTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + } } diff --git a/charts/opskubedbcom-kafkaopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-kafkaopsrequest-editor/ui/create-ui.yaml index 29999255ff..94036d0885 100644 --- a/charts/opskubedbcom-kafkaopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-kafkaopsrequest-editor/ui/create-ui.yaml @@ -1,563 +1,567 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|Combined|horizontalScaling - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/node - type: input - - elements: - - computed: setValueFromDbDetails|/spec/topology/broker/replicas - label: - text: Broker - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/broker - type: input - - computed: setValueFromDbDetails|/spec/topology/controller/replicas - label: - text: Controller - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology/properties/controller - type: input - if: ifDbTypeEqualsTo|Topology|horizontalScaling - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/topology - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine-broker: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion elements: - - computed: setMachine|broker - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|broker|/spec/topology/broker/resources - schema: - $ref: discriminator#/machine-broker - type: select - - if: isMachineCustom|/machine-broker - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/broker/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/broker/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/broker/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/broker/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/broker/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: Broker - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/broker - show_label: true - type: single-step-form - - discriminator: - machine-controller: - default: "" - type: string + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - computed: setMachine|controller - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|controller|/spec/topology/controller/resources - schema: - $ref: discriminator#/machine-controller - type: select - - if: isMachineCustom|/machine-controller - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/controller/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/controller/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/controller/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/controller/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/controller/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: Controller - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/controller - show_label: true - type: single-step-form - - discriminator: - machine-node: - default: "" - type: string + - type: input-compare + label: Node + if: + type: function + name: ifDbTypeEqualsTo|Combined|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/node + - type: block-layout + label: Topology horizontal scaling + if: + name: ifDbTypeEqualsTo|Topology|horizontalScaling + type: function + elements: + - type: block-layout + label: Broker Horizontal Scaling + showLabels: false + elements: + - type: label-element + label: Broker + - type: input-compare + label: Replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/broker + init: + type: func + value: setValueFromDbDetails|/spec/topology/broker/replicas + - type: block-layout + label: Controller Horizontal Scaling + showLabels: false + elements: + - type: label-element + label: Controller + - type: input-compare + label: Replicas + init: + type: func + value: setValueFromDbDetails|/spec/topology/controller/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/topology/properties/controller +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - computed: setMachine|node - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|node|/spec/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-node - type: select - - if: isMachineCustom|/machine-node - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Combined|VerticalScaling - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - elements: - - computed: setValueFromDbDetails|/spec/topology/broker/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/broker - type: input - validationRuleObject: - func: checkVolume|/spec/topology/broker/storage/resources/requests/storage|/spec/volumeExpansion/broker - if: ifDbTypeEqualsTo|Topology|VolumeExpansion - label: - text: Broker - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/topology/controller/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/controller - type: input - validationRuleObject: - func: checkVolume|/spec/topology/controller/storage/resources/requests/storage|/spec/volumeExpansion/controller - if: ifDbTypeEqualsTo|Topology|VolumeExpansion - label: - text: Controller - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/node - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node - if: ifDbTypeEqualsTo|Combined|VolumeExpansion - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/volumeExpansion - show_label: true - type: single-step-form - - label: - text: Mode - options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: block-layout + label: Combined Vertical Scaling + showLabels: false + if: + type: function + name: ifDbTypeEqualsTo|Combined|verticalScaling + elements: + - type: machine-compare + label: Resources + loader: getMachines|node + init: + type: func + value: setMachine|node + watcher: + func: onMachineChange|node|/spec/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value + - type: block-layout + if: + type: function + name: ifDbTypeEqualsTo|Topology|verticalScaling + label: Topology Vertical Scaling + showLabels: false + elements: + - type: block-layout + label: Broker Vertical Scaling + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|broker + init: + type: func + value: setMachine|broker + watcher: + func: onMachineChange|broker|/spec/topology/broker/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/broker/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/broker/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/broker/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/broker/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/broker/properties/topology/properties/value + - type: block-layout + label: Controller Vertical Scaling + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|controller + init: + type: func + value: setMachine|controller + watcher: + func: onMachineChange|controller|/spec/topology/controller/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/controller/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/controller/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/controller/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/controller/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/controller/properties/topology/properties/value +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: input-compare + label: Node + if: + type: function + name: ifDbTypeEqualsTo|Combined|volumeExpansion + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node + schema: schema/properties/spec/properties/volumeExpansion/properties/node + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode + - type: block-layout + label: Topology volume expansion + if: + type: function + name: ifDbTypeEqualsTo|Topology|volumeExpansion elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: input-compare + label: Broker + init: + type: func + value: setValueFromDbDetails|/spec/topology/broker/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/broker/storage/resources/requests/storage|/spec/volumeExpansion/broker + schema: schema/properties/spec/properties/volumeExpansion/properties/broker + - type: input-compare + label: Controller + init: + type: func + value: setValueFromDbDetails|/spec/topology/controller/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/controller/storage/resources/requests/storage|/spec/volumeExpansion/controller + schema: schema/properties/spec/properties/volumeExpansion/properties/controller +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-object-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + elements: + - type: input + label: organization + schema: schema/items/properties/subject/properties/organizations/items + - type: array-object-form + label: countries + schema: schema/items/properties/subject/properties/countries + elements: + - type: input + label: country + schema: schema/items/properties/subject/properties/countries/items + - type: array-object-form + label: organizational_units + schema: schema/items/properties/subject/properties/organizationalUnits + elements: + - type: input + label: organizational_unit + schema: schema/items/properties/subject/properties/organizationalUnits/items + - type: array-object-form + label: provinces + schema: schema/items/properties/subject/properties/provinces + elements: + - type: input + label: province + schema: schema/items/properties/subject/properties/provinces/items + - type: array-object-form + label: DNS Names + schema: schema/items/properties/dnsNames + elements: + - type: input + label: dns name + schema: schema/items/properties/dnsNames/items + - type: array-object-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + elements: + - type: input + label: ip Address + schema: schema/items/properties/ipAddresses/items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-kafkaopsrequest-editor/ui/functions.js b/charts/opskubedbcom-kafkaopsrequest-editor/ui/functions.js index e3e47f2a40..21010238e2 100644 --- a/charts/opskubedbcom-kafkaopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-kafkaopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,1019 +305,1038 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/kafkas`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} + } -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + function returnFalse() { + return false + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/kafkas/${name}` - const resp = await axios.get(url) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resp.data || {} - } else return {} -} - -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.Kafka?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/kafkaversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/kafkas`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredKafkaVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredKafkaVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/kafkas/${name}` + const resp = await axios.get(url) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + setDiscriminatorValue('/dbDetails', resp.data || {}) + + return resp.data || {} + } else return {} + } + + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.Kafka?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/kafkaversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredKafkaVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredKafkaVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } - return selectedType === type -} + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + return selectedType === type } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) }) + } - if (dbType === 'Standalone') return true - else return false - } else return false -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + return spec?.tls || undefined + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + const { spec } = dbDetails || {} + const { topology } = spec || {} -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + if (topology) { + return 'Topology' + } else { + return 'Combined' + } + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType({ + discriminator, + getValue, + }) -function asDatabaseOperation(route) { - return !!route.params.actions -} + if (dbType === 'Combined') return true + else return false + } else return false + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } + + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function clearOpsReqSpec(verd, opsReqType) { + if ( + opsReqType === 'verticalScaling' || + opsReqType === 'horizontalScaling' || + opsReqType === 'volumeExpansion' || + opsReqType === 'configuration' + ) { + if (verd === 'Topology') { + commit('wizard/model$delete', `/spec/${opsReqType}/node`) + } else if (verd === 'Combined') { + commit('wizard/model$delete', `/spec/${opsReqType}/broker`) + commit('wizard/model$delete', `/spec/${opsReqType}/controller`) + commit('wizard/model$delete', `/spec/${opsReqType}/topology`) + } + } + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function asDatabaseOperation() { + return !!route.params.actions + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return !ver + } -// machine profile stuffs -let machinesFromPreset = [] -function hasMachine({ getValue, discriminator }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - return !!annotations['kubernetes.io/instance-type'] -} + // // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } - }) - .filter((val) => !!val) + clearOpsReqSpec(verd, opsReqType) + return value === verd } - return arr -} -function setMachine({ getValue, discriminator, storeGet }, type) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + // // machine profile stuffs + // let machinesFromPreset = [] + + function getMachines(type) { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = (type && type !== 'node' + ? dbDetails?.spec?.topology?.[type]?.resources?.requests + : dbDetails?.spec?.podTemplate?.spec?.containers?.[0]?.resources?.requests) || { + cpu: '', + memory: '', + } + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } + }) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - const machine = parsedInstance[type] || 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function setMachine(type) { + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = (type && type !== 'node' + ? dbDetails?.spec?.topology?.[type]?.resources?.requests + : dbDetails?.spec?.podTemplate?.spec?.containers?.[0]?.resources?.requests) || { + cpu: '', + memory: '', + } + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance[type] || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, `/machine-${type}`) - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine-${type}`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - if (selectedMachine === 'custom') delete parsedInstance[type] - else parsedInstance[type] = selectedMachine - annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - if (machinesFromPreset.length) - commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, - force: true, - }) + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + if (selectedMachine === 'custom') delete parsedInstance[type] + else parsedInstance[type] = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) - if (parsedInstance && Object.keys(parsedInstance).length === 0) - commit('wizard/model$delete', '/metadata/annotations') -} + if (parsedInstance && Object.keys(parsedInstance).length === 0) + commit('wizard/model$delete', '/metadata/annotations') + } -function isMachineCustom({ watchDependency, getValue, discriminator }, path) { - watchDependency(`discriminator#${path}`) - const machine = getValue(discriminator, `${path}`) - return machine === 'custom' -} + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } + + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} - -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + const watchPath = `discriminator#/reconfigurationType` + // watchDependency(watchPath) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const configPath = `/applyConfig` + const applyconfig = getValue(discriminator, configPath) + + const configObj = {} -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: `/spec/configuration/applyConfig`, + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + setDiscriminatorValue(`/applyConfig`, []) + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} - -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} - -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - - return verd -} -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + function isIssuerRefRequired() { + const hasTls = hasTlsField() - return !hasTls -} + return !hasTls + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -// ************************************** Set db details ***************************************** + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + return !dbDetails || !dbName + } - return !dbDetails || !dbName -} + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - const retValue = getValue(discriminator, `/dbDetails${path}`) + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name } - return retValue || undefined -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function setResource({ discriminator, getValue, watchDependency }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0].resources -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } -function setApplyToIfReady() { - return 'IfReady' -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + const value = parseFloat(match[1]) + const unit = match[2] - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/kafka/topology` + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + return value * units[unit] } -} -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function disableAlias() { + return !!(model && model.alias) } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') - - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - - return value * units[unit] -} - -return { - isRancherManaged, - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + clearOpsReqSpec, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-mariadbopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-mariadbopsrequest-editor/ui/create-ui.yaml index 12516d2cbc..02a1e6b008 100644 --- a/charts/opskubedbcom-mariadbopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-mariadbopsrequest-editor/ui/create-ui.yaml @@ -1,413 +1,471 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|cluster|horizontalScaling - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/member - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|mariadb|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mariadb/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mariadb/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey: - default: "" - type: string - topologyValue: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyKey - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyValue - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - label: - text: labels.mariadb - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mariadb - show_label: true - type: single-step-form - - computed: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources|/spec/verticalScaling/exporter/resources - label: - text: labels.exporter - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter/properties/resources - type: resource-input-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mariadb - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/mariadb - - label: - text: Mode +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling + elements: + - type: input-compare + label: Replicas + if: + type: function + name: ifDbTypeEqualsTo|cluster|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/member +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|mariadb|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/mariadb/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/mariadb/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/mariadb/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue + - type: horizontal-layout + showLabels: true + label: Exporter + elements: + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/cpu|/spec/verticalScaling/exporter/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/cpu|/spec/verticalScaling/exporter/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/memory|/spec/verticalScaling/exporter/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/memory|/spec/verticalScaling/exporter/resources/limits/memory +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/mariadb + schema: schema/properties/spec/properties/volumeExpansion/properties/mariadb + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: switch + label: Require SSL + init: + type: func + value: setValueFromDbDetails|/spec/requireSSL + if: + name: showIssuerRefAndCertificates + type: function + schema: schema/properties/spec/properties/tls/properties/requireSSL + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: setValueFromDbDetails|/spec/requireSSL - label: - text: labels.require_ssl_question - schema: - $ref: schema#/properties/spec/properties/tls/properties/requireSSL - type: switch - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always \ No newline at end of file diff --git a/charts/opskubedbcom-mariadbopsrequest-editor/ui/functions.js b/charts/opskubedbcom-mariadbopsrequest-editor/ui/functions.js index 8b302af039..390fc9b63a 100644 --- a/charts/opskubedbcom-mariadbopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-mariadbopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,999 +305,1018 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mariadbs`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mariadbs/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.MariaDB?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/mariadbversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mariadbs`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredMariaDBVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredMariaDBVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mariadbs/${name}` + const resp = await axios.get(url) + + setDiscriminatorValue('/dbDetails', resp.data || {}) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.MariaDB?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/mariadbversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredMariaDbVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredMariaDbVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } + + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') + + return selectedType === type + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } + + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) }) + } - if (dbType === 'standalone') return true - else return false - } else return false -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + return spec?.tls || undefined + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + const { replicas } = spec || {} + let verd = '' - const { spec } = dbDetails || {} - const { replicas } = spec || {} - let verd = '' + if (replicas > 1) { + verd = 'cluster' + } else { + verd = 'standalone' + } - if (replicas > 1) { - verd = 'cluster' - } else { - verd = 'standalone' + return verd } - return verd -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType({ + discriminator, + getValue, + }) -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + if (dbType === 'standalone') return true + else return false + } else return false + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function asDatabaseOperation() { + return !!route.params.actions + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } + + return !ver } - return !ver -} -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - - return value === verd -} + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() -// machine profile stuffs -let machinesFromPreset = [] + return value === verd + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // machine profile stuffs + // let machinesFromPreset = [] + + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const machine = annotations['kubernetes.io/instance-type'] || 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} - -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return { machine } + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + if (obj && Object.keys(obj).length) commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: path, + value: obj, force: true, }) + + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') + else { + annotations['kubernetes.io/instance-type'] = selectedMachine + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + } } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function isMachineCustom() { + // watchDependency(`discriminator#/machine`) + const machine = getValue(discriminator, `/machine`) + return machine === 'custom' + } -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} - -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - - return reconfigurationType === value -} -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } - const configObj = {} + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + const watchPath = `discriminator#/reconfigurationType` + // watchDependency(watchPath) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') + + const configObj = {} -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: `/spec/configuration/applyConfig`, + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + setDiscriminatorValue(`/applyConfig`, []) + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') + if (apiGroup) return apiGroup + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/remove') + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, + }) + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/rotateCertificates') } } -} - -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + function isIssuerRefRequired() { + const hasTls = hasTlsField() - return verd -} - -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + return !hasTls + } - return !hasTls -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ - discriminator, - model, - getValue, - watchDependency, - }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -// ************************************** Set db details ***************************************** + return !dbDetails || !dbName + } -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) - return !dbDetails || !dbName -} + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - const retValue = getValue(discriminator, `/dbDetails${path}`) + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') } - return retValue || undefined -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function isVerticalScaleTopologyRequired() { + // watchDependency(`discriminator#/topologyKey`) + // watchDependency(`discriminator#/topologyValue`) -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + const key = getValue(discriminator, `/topologyKey`) + const value = getValue(discriminator, `/topologyValue`) + const path = `/spec/verticalScaling/mariadb/topology` -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function setApplyToIfReady() { - return 'IfReady' -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/mariadb/topology` + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false - } -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + const value = parseFloat(match[1]) + const unit = match[2] - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + return value * units[unit] } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } - return value * units[unit] -} + function disableAlias() { + return !!(model && model.alias) + } -return { - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-memcachedopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-memcachedopsrequest-editor/ui/create-ui.yaml index f76693a10b..6d7a4a2437 100644 --- a/charts/opskubedbcom-memcachedopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-memcachedopsrequest-editor/ui/create-ui.yaml @@ -1,295 +1,260 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|Combined|horizontalScaling - label: - text: Replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/replicas - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|memcached|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/memcached/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/memcached/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/memcached/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/memcached/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/memcached/properties/topology - show_label: true - type: single-step-form - label: - text: Memcached - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/memcached - show_label: true - type: single-step-form - - computed: setResource|/spec/podTemplate/spec/containers - label: - text: Exporter - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter/properties/resources - type: resource-input-form - - label: - text: Readiness Criteria - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/readinessCriteria - type: input - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: input-compare + label: Replicas + if: + type: function + name: ifDbTypeEqualsTo|Combined|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/replicas +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: block-layout + label: Memcached Vertical Scaling + showLabels: false elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|memcached|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/memcached/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/memcached/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/memcached/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-memcachedopsrequest-editor/ui/functions.js b/charts/opskubedbcom-memcachedopsrequest-editor/ui/functions.js index cbde06300c..1f25b9f1c1 100644 --- a/charts/opskubedbcom-memcachedopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-memcachedopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,949 +305,845 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} +let machinesFromPreset = [] -function returnFalse() { - return false -} +export const useFunc = (model) => { + const route = store.state?.route -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + getDbDetails() + showAndInitOpsRequestType() - const resources = (resp && resp.data && resp.data.items) || [] + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/memcacheds`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/memcacheds/${name}`, - ) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.Memcached?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/memcachedversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/memcacheds`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredMemcachedVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredMemcachedVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 - - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher - } - return 0 // versions are equal -} - -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/memcacheds/${name}` + const resp = await axios.get(url) - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + setDiscriminatorValue('/dbDetails', resp.data || {}) - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + return resp.data || {} + } else return {} } - return true -} - -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') - return selectedType === type -} - -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.Memcached?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/memcachedversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredMemcachedVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredMemcachedVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 - if (dbType === 'Standalone') return true - else return false - } else return false -} - -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + return selectedType === type + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + const { spec } = dbDetails || {} + return spec?.tls || undefined + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType({ + discriminator, + getValue, + }) - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) - } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + if (dbType === 'Standalone') return true + else return false + } else return false } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', - } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name } - return !ver -} - -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} - -// machine profile stuffs -let machinesFromPreset = [] - -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } - }) - .filter((val) => !!val) + function asDatabaseOperation() { + return !!route.params.actions } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - const path = `/spec/verticalScaling/${type}/resources` + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + if (ver) { + // For kubedb-ui commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), force: true, }) + } + return !ver } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + return !ver + } - const secrets = (resp && resp.data && resp.data.items) || [] + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } - const filteredSecrets = secrets + return !ver + } - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + return !ver } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() + + return value === verd + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // machine profile stuffs + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + } + }) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') return { text: machine, value: { machine } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = instance || {} + } + const machine = parsedInstance || 'custom' - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + const path = `/spec/verticalScaling/${type}/resources` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) - } + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = instance || {} + } + if (selectedMachine === 'custom') parsedInstance = undefined + else parsedInstance = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + + if ( + !parsedInstance || + (typeof parsedInstance === 'object' && Object.keys(parsedInstance).length === 0) + ) + commit('wizard/model$delete', '/metadata/annotations') } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) - return reconfigurationType === value -} + const secrets = (resp && resp.data && resp.data.items) || [] -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + const filteredSecrets = secrets - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) + return filteredSecrets } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} - -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, - force: true, - }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} - -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) - return !!tls -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } - } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) } - return clusterIssuers + + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }) - return resources + + const items = (resp && resp.data && resp.data.items) || [] + ans = items } catch (e) { console.log(e) - return [] } - } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + return ans + } + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, + }) - commit('wizard/model$delete', '/spec/tls') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') } -} + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - return verd -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') - return !hasTls -} + const watchPath = `discriminator#/reconfigurationType` + // watchDependency(watchPath) + return reconfigurationType === value + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -// ************************************** Set db details ***************************************** + const configObj = {} -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } - return !dbDetails || !dbName -} + commit('wizard/model$update', { + path: `/spec/configuration/applyConfig`, + value: configObj, + force: true, + }) + } -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + function onReconfigurationTypeChange() { + setDiscriminatorValue('/applyConfig', []) + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - const retValue = getValue(discriminator, `/dbDetails${path}`) + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + return !dbDetails || !dbName } - return retValue || undefined -} + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) -function setResource({ discriminator, getValue, watchDependency }, path) { - watchDependency('discriminator#/dbDetails') - const resources = getValue(discriminator, `/dbDetails${path}`) || {} - return resources -} + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function setApplyToIfReady() { - return 'IfReady' -} + function setApplyToIfReady() { + return 'IfReady' + } -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + function isVerticalScaleTopologyRequired() { + // watchDependency(`discriminator#/topologyKey`) + // watchDependency(`discriminator#/topologyValue`) - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/memcached/topology` + const key = getValue(discriminator, `/topologyKey`) + const value = getValue(discriminator, `/topologyValue`) + const path = `/spec/verticalScaling/memcached/topology` - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } } -} -return { - isRancherManaged, - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, + return { + fetchJsons, + returnFalse, + isRancherManaged, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + } } diff --git a/charts/opskubedbcom-mongodbopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-mongodbopsrequest-editor/ui/create-ui.yaml index a211266067..c4d55bfb70 100644 --- a/charts/opskubedbcom-mongodbopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-mongodbopsrequest-editor/ui/create-ui.yaml @@ -1,1106 +1,1003 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|replicaSet|horizontalScaling - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/replicas - type: input - - elements: - - elements: - - label: - text: labels.configServer - type: label-element - - computed: setValueFromDbDetails|/spec/shardTopology/configServer/replicas - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/configServer/properties/replicas - type: input - label: - text: Config Server horizontal Scaling - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/configServer - type: single-step-form - - elements: - - label: - text: labels.mongos - type: label-element - - computed: setValueFromDbDetails|/spec/shardTopology/mongos/replicas - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/mongos/properties/replicas - type: input - label: - text: Mongos horizontal Scaling - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/mongos - type: single-step-form - - elements: - - label: - text: labels.shard - type: label-element - - computed: setValueFromDbDetails|/spec/shardTopology/shard/replicas - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/shard/properties/replicas - type: input - - computed: setValueFromDbDetails|/spec/shardTopology/shard/shards - label: - text: labels.shards - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/shard/properties/shards - type: input - label: - text: Shard horizontal Scaling - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/shard - type: single-step-form - if: ifDbTypeEqualsTo|sharded|horizontalScaling - label: - text: 'Sharded horizontal scaling ' - type: single-step-form - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine-standalone: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + paths: + - schema/properties/spec/properties/databaseRef/properties/name + func: onDbChange + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: onRequestTypeChange + paths: + - schema/properties/spec/properties/type + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion elements: - - computed: setMachine|standalone - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|standalone|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine-standalone - type: select - - if: isMachineCustom|/machine-standalone - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/standalone/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/standalone/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-standalone: - default: "" - type: string - topologyValue-standalone: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|standalone - schema: - $ref: discriminator#/topologyKey-standalone - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|standalone - schema: - $ref: discriminator#/topologyValue-standalone - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|standalone|verticalScaling - label: - text: Standalone vertical scaling - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/standalone - show_label: true - type: single-step-form - - discriminator: - machine-replicaSet: - default: "" - type: string + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - computed: setMachine|replicaSet - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|replicaSet|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine-replicaSet - type: select - - if: isMachineCustom|/machine-replicaSet - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/replicaSet/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/replicaSet/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-replicaSet: - default: "" - type: string - topologyValue-replicaSet: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|replicaSet - schema: - $ref: discriminator#/topologyKey-replicaSet - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|replicaSet - schema: - $ref: discriminator#/topologyValue-replicaSet - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|replicaSet|verticalScaling - label: - text: Replicaset vertical scaling - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/replicaSet - show_label: true - type: single-step-form - - elements: - - discriminator: - machine-configServer: - default: "" - type: string - elements: - - computed: setMachine|configServer - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|configServer|/spec/shardTopology/configServer/podTemplate/spec/resources - schema: - $ref: discriminator#/machine-configServer - type: select - - if: isMachineCustom|/machine-configServer - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/configServer/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/configServer/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-configServer: - default: "" - type: string - topologyValue-configServer: - default: "" - type: string + - type: input-compare + label: Replicas + if: + type: function + name: ifDbTypeEqualsTo|replicaSet|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/replicas + - type: block-layout + label: 'Sharded horizontal scaling' + if: + name: ifDbTypeEqualsTo|sharded|horizontalScaling + type: function elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|configServer - schema: - $ref: discriminator#/topologyKey-configServer - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|configServer - schema: - $ref: discriminator#/topologyValue-configServer - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - label: - text: Config Server Vertical Scaling - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/configServer - show_label: true - type: single-step-form - - discriminator: - machine-mongos: - default: "" - type: string - elements: - - computed: setMachine|mongos - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|mongos|/spec/shardTopology/mongos/podTemplate/spec/resources - schema: - $ref: discriminator#/machine-mongos - type: select - - if: isMachineCustom|/machine-mongos - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mongos/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mongos/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-mongos: - default: "" - type: string - topologyValue-mongos: - default: "" - type: string + - type: block-layout + label: Config Server horizontal Scaling + showLabels: false + elements: + - type: label-element + label: Config Server + - type: input-compare + label: Replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/configServer/properties/replicas + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/configServer/replicas + - type: block-layout + label: Mongo Horizontal Scaling + showLabels: false + elements: + - type: label-element + label: Mongos + - type: input-compare + label: Replicas + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/mongos/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/mongos/properties/replicas + - type: block-layout + label: Shard horizontal Scaling + showLabels: false + elements: + - type: label-element + label: Shard + - type: input-compare + label: Replicas + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/shard/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/shard/properties/replicas + - type: input + label: Shards + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/shard/shards + schema: schema/properties/spec/properties/horizontalScaling/properties/shard/properties/shards +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: block-layout + label: Standalone Vertical Scaling + showLabels: false + if: + type: function + name: ifDbTypeEqualsTo|standalone|verticalScaling elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|mongos - schema: - $ref: discriminator#/topologyKey-mongos - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|mongos - schema: - $ref: discriminator#/topologyValue-mongos - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - label: - text: Mongos Vertical Scaling - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mongos - show_label: true - type: single-step-form - - discriminator: - machine-shard: - default: "" - type: string - elements: - - computed: setMachine|shard - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|shard|/spec/shardTopology/shard/podTemplate/spec/resources - schema: - $ref: discriminator#/machine-shard - type: select - - if: isMachineCustom|/machine-shard - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/shard/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/shard/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey-shard: - default: "" - type: string - topologyValue-shard: - default: "" - type: string + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine|standalone + watcher: + func: onMachineChange|standalone|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/standalone/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/standalone/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/standalone/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|standalone + schema: temp/topologyKey-standalone + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|standalone + schema: temp/topologyValue-standalone + - type: block-layout + label: ReplicaSet Vertical Scaling + if: + type: function + name: ifDbTypeEqualsTo|replicaSet|verticalScaling elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired|shard - schema: - $ref: discriminator#/topologyKey-shard - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired|shard - schema: - $ref: discriminator#/topologyValue-shard - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - label: - text: Shard Vertical Scaling - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/shard - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|sharded|verticalScaling - label: - text: 'Sharded vertical scaling ' - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - if: ifDbTypeEqualsTo|standalone|volumeExpansion - label: - text: labels.standalone - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/standalone - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/standalone - - label: - text: Mode - options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - if: ifDbTypeEqualsTo|replicaSet|volumeExpansion - label: - text: labels.replicaSet - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/replicaSet - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/replicaSet - - elements: - - computed: setValueFromDbDetails|/spec/shardTopology/configServer/storage/resources/requests/storage - label: - text: labels.configServer - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/configServer - type: input - validationRuleObject: - func: checkVolume|/spec/shardTopology/configServer/storage/resources/requests/storage|/spec/volumeExpansion/configServer - - computed: setValueFromDbDetails|/spec/shardTopology/shard/storage/resources/requests/storage - label: - text: labels.shard - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/shard - type: input - validationRuleObject: - func: checkVolume|/spec/shardTopology/shard/storage/resources/requests/storage|/spec/volumeExpansion/shard - if: ifDbTypeEqualsTo|sharded|volumeExpansion - label: - text: Sharded volume expansion - type: single-step-form - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string - elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange|standalone - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/standalone/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Standalone configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/standalone/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: standalone/applyConfig - type: array + - type: machine-compare + label: Resources + init: + type: func + value: setMachine|replicaSet + loader: getMachines + watcher: + func: onMachineChange|replicaSet|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/replicaSet/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/replicaSet/properties/resources + - type: select + label: Node Selection Policy + schema: schema/properties/spec/properties/verticalScaling/properties/replicaSet/properties/nodeSelectionPolicy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|replicaSet + schema: temp/topologyKey-replicaSet + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|replicaSet + schema: temp/topologyValue-replicaSet + - type: block-layout + if: + type: function + name: ifDbTypeEqualsTo|sharded|verticalScaling + label: Sharded Vertical Scaling + showLabels: false elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange|standalone - required: true - schema: - $ref: discriminator#/properties/standalone/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/standalone/properties/removeCustomConfig - type: switch - if: ifDbTypeEqualsTo|standalone|configuration - label: - text: labels.standalone - schema: - $ref: schema#/properties/spec/properties/configuration/properties/standalone - show_label: true - type: single-step-form - - discriminator: - reconfigurationType: - type: string + - type: block-layout + label: Config Server Vertical Scaling + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine|configServer + watcher: + func: onMachineChange|configServer|/spec/shardTopology/configServer/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/configServer/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/configServer/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/configServer/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|configServer + schema: temp/topologyKey-configServer + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|configServer + schema: temp/topologyValue-configServer + - type: block-layout + label: Mongos Vertical Scaling + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine|mongos + watcher: + func: onMachineChange|mongos|/spec/shardTopology/mongos/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/mongos/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/mongos/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/mongos/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|mongos + schema: temp/topologyKey-mongos + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|mongos + schema: temp/topologyValue-mongos + - type: block-layout + label: Shard Vertical Scaling + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine|shard + watcher: + func: onMachineChange|shard|/spec/shardTopology/shard/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/shard/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/shard/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/shard/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired|shard + schema: temp/topologyKey-shard + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired|shard + schema: temp/topologyValue-shard +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange|replicaSet - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/replicaSet/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Replica Set configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/replicaSet/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: replicaSet/applyConfig - type: array + - type: input-compare + label: Standalone + if: + type: function + name: ifDbTypeEqualsTo|standalone|volumeExpansion + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/standalone + schema: schema/properties/spec/properties/volumeExpansion/properties/standalone + - type: input-compare + label: ReplicaSet + if: + type: function + name: ifDbTypeEqualsTo|replicaSet|volumeExpansion + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/replicaSet + schema: schema/properties/spec/properties/volumeExpansion/properties/replicaSet + - type: block-layout + label: Sharded volume expansion + if: + type: function + name: ifDbTypeEqualsTo|sharded|volumeExpansion elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange|replicaSet - required: true - schema: - $ref: discriminator#/properties/replicaSet/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/replicaSet/properties/removeCustomConfig - type: switch - if: ifDbTypeEqualsTo|replicaSet|configuration - label: - text: labels.replicaSet - schema: - $ref: schema#/properties/spec/properties/configuration/properties/replicaSet - show_label: true - type: single-step-form - - elements: - - discriminator: - reconfigurationType-configServer: - type: string - elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange|configServer|true + - type: input-compare + label: Config Server + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/configServer/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/shardTopology/configServer/storage/resources/requests/storage|/spec/volumeExpansion/configServer + schema: schema/properties/spec/properties/volumeExpansion/properties/configServer + - type: input-compare + label: Shard + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/shard/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/shardTopology/shard/storage/resources/requests/storage|/spec/volumeExpansion/shard + schema: schema/properties/spec/properties/volumeExpansion/properties/shard + - type: select + label: Mode options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/reconfigurationType-configServer - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/shardTopology/configServer/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configServer/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret|configServer|true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configServer/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: configServer/applyConfig - type: array + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Standalone + if: + name: ifDbTypeEqualsTo|standalone|configuration + type: function + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange|standalone + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Standalone config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/standalone/properties/configSecret/properties/name + - type: object-item + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange|standalone + paths: + - temp/properties/standalone/applyConfig + schema: temp/properties/standalone/applyConfig + # elements: + # - type: input + # label: key + # validation: + # type: required + # schema: temp/properties/configArray/items/properties/key + # - type: textarea + # label: value + # validation: + # type: required + # schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/standalone/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function + - type: block-layout + label: Replica Set + if: + name: ifDbTypeEqualsTo|replicaSet|configuration + type: function + elements: + - type: radio + label: Reconfigure Type + validation: + type: required + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + schema: temp/properties/reconfigurationType + watcher: + func: onReconfigurationTypeChange|replicaSet + paths: + - temp/properties/reconfigurationType + - type: block-layout + label: Replica Set config secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + schema: schema/properties/spec/properties/configuration/properties/replicaSet/properties/configSecret/properties/name + validation: + type: required + refresh: true + label: Config Secret + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + - type: array-object-form + label: ApplyConfig + schema: temp/properties/replicaSet/applyConfig + validation: + type: required + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + watcher: + func: onApplyconfigChange|replicaSet + paths: + - temp/properties/replicaSet/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: textarea + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/replicaSet/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function + - type: block-layout + elements: + - type: block-layout + label: Config Server + showLabels: true elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig|configServer|true - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange|configServer - required: true - schema: - $ref: discriminator#/properties/configServer/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configServer/properties/removeCustomConfig - type: switch - label: - text: labels.configServer - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configServer - show_label: true - type: single-step-form - - discriminator: - reconfigurationType-mongos: - type: string - elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange|mongos|true - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/reconfigurationType-mongos - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/shardTopology/mongos/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mongos/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret|mongos|true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mongos/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: mongos/applyConfig - type: array + - type: radio + label: Reconfigure Type + validation: + type: required + schema: temp/properties/reconfigurationType-configServer + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange|configServer|true + paths: + - temp/properties/reconfigurationType-configServer + - type: block-layout + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret|configServer|true + type: function + elements: + - type: select + label: Config Secret + schema: schema/properties/spec/properties/configuration/properties/configServer/properties/configSecret/properties/name + validation: + type: required + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/configServer/configSecret/name + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + refresh: true + addNewButton: + label: Create Config + target: _blank + url: + function: createSecretUrl + - type: array-object-form + label: Apply Config + schema: temp/properties/configServer/applyConfig + validation: + type: required + if: + name: ifReconfigurationTypeEqualsTo|applyConfig|configServer|true + type: function + watcher: + func: onApplyconfigChange|configServer + paths: + - temp/properties/configServer/applyConfig + elements: + - type: input + label: Key + schema: temp/properties/configArray/items/properties/key + validation: + type: required + - type: textarea + label: Value + schema: temp/properties/configArray/items/properties/value + validation: + type: required + + - type: switch + label: Remove CustomConfig + schema: schema/properties/spec/properties/configuration/properties/configServer/properties/removeCustomConfig + if: + name: returnFalse + type: function + - type: block-layout + label: Mongos + showLabels: true elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig|mongos|true - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange|mongos - required: true - schema: - $ref: discriminator#/properties/mongos/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mongos/properties/removeCustomConfig - type: switch - label: - text: labels.mongos - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mongos - show_label: true - type: single-step-form - - discriminator: - reconfigurationType-shard: - type: string - elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange|shard|true - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/reconfigurationType-shard - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/shardTopology/shard/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/shard/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret|shard|true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/shard/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: shard/applyConfig - type: array + - type: radio + label: Reconfigure Type + validation: + type: required + schema: temp/properties/reconfigurationType-mongos + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange|mongos|true + paths: + - temp/properties/reconfigurationType-mongos + - type: block-layout + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret|mongos|true + type: function + elements: + - type: select + label: Config Secret + schema: schema/properties/spec/properties/configuration/properties/mongos/properties/configSecret/properties/name + validation: + type: required + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/mongos/configSecret/name + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + refresh: true + addNewButton: + label: Create Config + target: _blank + url: + function: createSecretUrl + - type: array-object-form + label: Apply Config + schema: temp/properties/mongos/applyConfig + validation: + type: required + if: + name: ifReconfigurationTypeEqualsTo|applyConfig|mongos|true + type: function + watcher: + func: onApplyconfigChange|mongos + paths: + - temp/properties/mongos/applyConfig + elements: + - type: input + label: Key + schema: temp/properties/configArray/items/properties/key + validation: + type: required + - type: textarea + label: Value + schema: temp/properties/configArray/items/properties/value + validation: + type: required + - type: switch + label: Remove CustomConfig + schema: schema/properties/spec/properties/configuration/properties/mongos/properties/removeCustomConfig + if: + name: returnFalse + type: function + - type: block-layout + label: Shard + showLabels: true elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig|shard|true - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange|shard - required: true - schema: - $ref: discriminator#/properties/shard/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/shard/properties/removeCustomConfig - type: switch - label: - text: labels.shard - schema: - $ref: schema#/properties/spec/properties/configuration/properties/shard - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|sharded|configuration - label: - text: Sharded Reconfigure form - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: radio + label: Reconfigure Type + validation: + type: required + schema: temp/properties/reconfigurationType-shard + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange|shard|true + paths: + - temp/properties/reconfigurationType-shard + + - type: block-layout + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret|shard|true + type: function + elements: + - type: select + label: Config Secret + schema: schema/properties/spec/properties/configuration/properties/shard/properties/configSecret/properties/name + validation: + type: required + init: + type: func + value: setValueFromDbDetails|/spec/shardTopology/shard/configSecret/name + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + refresh: true + addNewButton: + label: Create Config + target: _blank + url: + function: createSecretUrl + - type: array-object-form + label: Apply Config + schema: temp/properties/shard/applyConfig + validation: + type: required + if: + name: ifReconfigurationTypeEqualsTo|applyConfig|shard|true + type: function + watcher: + func: onApplyconfigChange|shard + paths: + - temp/properties/shard/applyConfig + elements: + - type: input + label: Key + schema: temp/properties/configArray/items/properties/key + validation: + type: required + - type: textarea + label: Value + schema: temp/properties/configArray/items/properties/value + validation: + type: required + - type: switch + label: Remove CustomConfig + schema: schema/properties/spec/properties/configuration/properties/shard/properties/removeCustomConfig + if: + name: returnFalse + type: function + label: Sharded Reconfigure form + if: + name: ifDbTypeEqualsTo|sharded|configuration + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + schema: temp/properties/tlsOperation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + watcher: + func: onTlsOperationChange + paths: + - temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-object-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + elements: + - type: input + label: organization + schema: schema/items/properties/subject/properties/organizations/items + - type: array-object-form + label: countries + schema: schema/items/properties/subject/properties/countries + elements: + - type: input + label: country + schema: schema/items/properties/subject/properties/countries/items + - type: array-object-form + label: organizational_units + schema: schema/items/properties/subject/properties/organizationalUnits + elements: + - type: input + label: organizational_unit + schema: schema/items/properties/subject/properties/organizationalUnits/items + - type: array-object-form + label: provinces + schema: schema/items/properties/subject/properties/provinces + elements: + - type: input + label: province + schema: schema/items/properties/subject/properties/provinces/items + - type: array-object-form + label: DNS Names + schema: schema/items/properties/dnsNames + elements: + - type: input + label: dns name + schema: schema/items/properties/dnsNames/items + - type: array-object-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + elements: + - type: input + label: ip Address + schema: schema/items/properties/ipAddresses/items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-mongodbopsrequest-editor/ui/functions.js b/charts/opskubedbcom-mongodbopsrequest-editor/ui/functions.js index 1831ab9a2a..71c90c661a 100644 --- a/charts/opskubedbcom-mongodbopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-mongodbopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,1046 +305,1061 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mongodbs`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} + } -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + function returnFalse() { + return false + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mongodbs/${name}` - const resp = await axios.get(url) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resp.data || {} - } else return {} -} - -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.MongoDB?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/mongodbversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mongodbs`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredMongoDbVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredMongoDbVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} - -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher - } - return 0 // versions are equal -} + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mongodbs/${name}` + const resp = await axios.get(url) -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] + setDiscriminatorValue('/dbDetails', resp.data || {}) - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + return resp.data || {} + } else return {} + } - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.MongoDB?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/mongodbversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredMongoDbVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredMongoDbVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', - } + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } - const { spec } = dbDetails || {} - return spec.tls || undefined -} + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - - const { spec } = dbDetails || {} - const { shardTopology, replicaSet } = spec || {} - let verd = '' - if (shardTopology) { - verd = 'sharded' - } else { - if (replicaSet) { - verd = 'replicaSet' - } else verd = 'standalone' + return selectedType === type } - return verd -} + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) }) + } - if (dbType === 'standalone') return true - else return false - } else return false -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function clearOpsReqSpec(verd, opsReqType, commit) { - if ( - opsReqType === 'verticalScaling' || - opsReqType === 'horizontalScaling' || - opsReqType === 'volumeExpansion' || - opsReqType === 'configuration' - ) { - if (verd === 'sharded') { - commit('wizard/model$delete', `/spec/${opsReqType}/replicaSet`) - commit('wizard/model$delete', `/spec/${opsReqType}/replicas`) - commit('wizard/model$delete', `/spec/${opsReqType}/standalone`) - } else if (verd === 'standalone') { - commit('wizard/model$delete', `/spec/${opsReqType}/replicaSet`) - commit('wizard/model$delete', `/spec/${opsReqType}/configServer`) - commit('wizard/model$delete', `/spec/${opsReqType}/mongos`) - commit('wizard/model$delete', `/spec/${opsReqType}/shard`) + const { spec } = dbDetails || {} + const { shardTopology, replicaSet } = spec || {} + let verd = '' + if (shardTopology) { + verd = 'sharded' } else { - commit('wizard/model$delete', `/spec/${opsReqType}/standalone`) - commit('wizard/model$delete', `/spec/${opsReqType}/configServer`) - commit('wizard/model$delete', `/spec/${opsReqType}/mongos`) - commit('wizard/model$delete', `/spec/${opsReqType}/shard`) + if (replicaSet) { + verd = 'replicaSet' + } else verd = 'standalone' } + + return verd } -} -function asDatabaseOperation(route) { - return !!route.params.actions -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType() -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + if (dbType === 'standalone') return true + else return false + } else return false + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function clearOpsReqSpec(verd, opsReqType) { + if ( + opsReqType === 'verticalScaling' || + opsReqType === 'horizontalScaling' || + opsReqType === 'volumeExpansion' || + opsReqType === 'configuration' + ) { + if (verd === 'sharded') { + commit('wizard/model$delete', `/spec/${opsReqType}/replicaSet`) + commit('wizard/model$delete', `/spec/${opsReqType}/replicas`) + commit('wizard/model$delete', `/spec/${opsReqType}/standalone`) + } else if (verd === 'standalone') { + commit('wizard/model$delete', `/spec/${opsReqType}/replicaSet`) + commit('wizard/model$delete', `/spec/${opsReqType}/configServer`) + commit('wizard/model$delete', `/spec/${opsReqType}/mongos`) + commit('wizard/model$delete', `/spec/${opsReqType}/shard`) + } else { + commit('wizard/model$delete', `/spec/${opsReqType}/standalone`) + commit('wizard/model$delete', `/spec/${opsReqType}/configServer`) + commit('wizard/model$delete', `/spec/${opsReqType}/mongos`) + commit('wizard/model$delete', `/spec/${opsReqType}/shard`) + } + } + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function asDatabaseOperation() { + return !!route.params.actions + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ discriminator, getValue, watchDependency }) + return !ver + } - clearOpsReqSpec(verd, opsReqType, commit) - return value === verd -} + // // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() -// machine profile stuffs -let machinesFromPreset = [] + clearOpsReqSpec(verd, opsReqType) + return value === verd + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // // machine profile stuffs + // let machinesFromPreset = [] + + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }, type) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function setMachine(type) { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance[type] || 'custom' + + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const machine = parsedInstance[type] || 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine-${type}`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, `/machine-${type}`) - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } - } + const path = `/spec/verticalScaling/${type}/resources` - const path = `/spec/verticalScaling/${type}/resources` + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + if (selectedMachine === 'custom') delete parsedInstance[type] + else parsedInstance[type] = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + if (parsedInstance && Object.keys(parsedInstance).length === 0) + commit('wizard/model$delete', '/metadata/annotations') } - if (selectedMachine === 'custom') delete parsedInstance[type] - else parsedInstance[type] = selectedMachine - annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) - - if (machinesFromPreset.length) - commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, - force: true, - }) - if (parsedInstance && Object.keys(parsedInstance).length === 0) - commit('wizard/model$delete', '/metadata/annotations') -} + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } -function isMachineCustom({ watchDependency, getValue, discriminator }, path) { - watchDependency(`discriminator#${path}`) - const machine = getValue(discriminator, `${path}`) - return machine === 'custom' -} + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} - -// reconfiguration type -function ifReconfigurationTypeEqualsTo( - { discriminator, getValue, watchDependency }, - value, - property, - isShard, -) { - let path = '/reconfigurationType' - if (isShard) path += `-${property}` - const reconfigurationType = getValue(discriminator, path) - const watchPath = `discriminator#${path}` - watchDependency(watchPath) - return reconfigurationType === value -} -function onApplyconfigChange({ discriminator, getValue, commit }, type) { - const configPath = `/${type}/applyConfig` - const applyconfig = getValue(discriminator, configPath) + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } - const configObj = {} + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value, property, isShard) { + let path = '/reconfigurationType' + if (isShard) path += `-${property}` + const reconfigurationType = getValue(discriminator, path) - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + const watchPath = `discriminator#${path}` + // watchDependency(watchPath) + return reconfigurationType === value } - commit('wizard/model$update', { - path: `/spec/configuration/${type}/applyConfig`, - value: configObj, - force: true, - }) -} + function onApplyconfigChange(type) { + const configPath = `/${type}/applyConfig` + const applyconfig = getValue(discriminator, configPath) -function onReconfigurationTypeChange( - { commit, discriminator, getValue, setDiscriminatorValue }, - property, - isShard, -) { - setDiscriminatorValue(`/${property}/applyConfig`, []) - let path = '/reconfigurationType' - if (isShard) path += `-${property}` - const reconfigurationType = getValue(discriminator, path) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration/${property}`) + const configObj = {} + + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/${property}/removeCustomConfig`, - value: true, + path: `/spec/configuration/${type}/applyConfig`, + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/${property}/configSecret`) - commit('wizard/model$delete', `/spec/configuration/${property}/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/${property}/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange(property, isShard) { + setDiscriminatorValue(`/${property}/applyConfig`, []) + let path = '/reconfigurationType' + if (isShard) path += `-${property}` + const reconfigurationType = getValue(discriminator, path) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration/${property}`) + + commit('wizard/model$update', { + path: `/spec/configuration/${property}/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/${property}/configSecret`) + commit('wizard/model$delete', `/spec/configuration/${property}/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/${property}/removeCustomConfig`) + } + } - return !!tls -} + // for tls + function hasTlsField() { + const tls = getDbTls() -function initIssuerRefApiGroup({ getValue, model, watchDependency }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + return !!tls + } - if (kind) { - return 'cert-manager.io' - } else return undefined -} + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + if (kind) { + return 'cert-manager.io' + } else return undefined + } - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} - -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) + return verd } -} - -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - return verd -} + function isIssuerRefRequired() { + const hasTls = hasTlsField() -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + return !hasTls + } - return !hasTls -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + return !dbDetails || !dbName + } - return !dbDetails || !dbName -} + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') - const retValue = getValue(discriminator, `/dbDetails${path}`) + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - if (commitPath) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace } - return retValue || undefined -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + function setApplyToIfReady() { + return 'IfReady' + } -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + function isVerticalScaleTopologyRequired(type) { + // watchDependency(`discriminator#/topologyKey-${type}`) + // watchDependency(`discriminator#/topologyValue-${type}`) -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + const key = getValue(discriminator, `/topologyKey-${type}`) + const value = getValue(discriminator, `/topologyValue-${type}`) + const path = `/spec/verticalScaling/${type}/topology` -function setApplyToIfReady() { - return 'IfReady' -} + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } + } -function isVerticalScaleTopologyRequired( - { watchDependency, getValue, discriminator, commit }, - type, -) { - watchDependency(`discriminator#/topologyKey-${type}`) - watchDependency(`discriminator#/topologyValue-${type}`) + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) - const key = getValue(discriminator, `/topologyKey-${type}`) - const value = getValue(discriminator, `/topologyValue-${type}`) - const path = `/spec/verticalScaling/${type}/topology` + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } } -} -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' - } -} + const value = parseFloat(match[1]) + const unit = match[2] + + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + return value * units[unit] } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } - const value = parseFloat(match[1]) - const unit = match[2] + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } - return value * units[unit] -} + function disableAlias() { + return !!(model && model.alias) + } -return { - isRancherManaged, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - disableOpsRequest, - initNamespace, - initDatabaseRef, - clearOpsReqSpec, - - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onDbChange, - onNamespaceChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + clearOpsReqSpec, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-mssqlserveropsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-mssqlserveropsrequest-editor/ui/create-ui.yaml index 3044be462e..03fb572d73 100644 --- a/charts/opskubedbcom-mssqlserveropsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-mssqlserveropsrequest-editor/ui/create-ui.yaml @@ -1,329 +1,362 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - label: - text: Replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/replicas - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|mssqlserver|/spec/podTemplate/spec/containers - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/topology - show_label: true - type: single-step-form - label: - text: MSSQLServer - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mssqlserver - show_label: true - type: single-step-form - - computed: setResource|/spec/podTemplate/spec/containers - label: - text: Exporter - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter/properties/resources - type: resource-input-form - - computed: setResource|/spec/podTemplate/spec/containers - label: - text: Coordinator - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources - type: resource-input-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mssqlserver - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/mssqlserver - label: - text: MSSQLServer - schema: - $ref: schema#/properties/spec/properties/volumeExpansion - show_label: true - type: single-step-form - - label: - text: Mode +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: onRequestTypeChange + paths: + - schema/properties/spec/properties/type + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: input-compare + label: Replicas + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/replicas +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: block-layout + label: MSSQLServer Vertical Scaling + showLabels: false elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|mssqlserver|/spec/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/mssqlserver/properties/topology/properties/value + # - type: block-layout + # label: Exporter + # showLabels: true + # elements: + # - type: input + # label: CPU + # schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/properties/cpu + # - type: input + # label: Memory + # schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/properties/memory + - type: horizontal-layout + showLabels: true + label: Exporter + elements: + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/cpu|/spec/verticalScaling/exporter/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/cpu|/spec/verticalScaling/exporter/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/memory|/spec/verticalScaling/exporter/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/memory|/spec/verticalScaling/exporter/resources/limits/memory + # - type: block-layout + # label: Coordinator + # showLabels: true + # elements: + # - type: input + # label: CPU + # schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/limits/properties/cpu + # - type: input + # label: Memory + # schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/limits/properties/memory + - type: horizontal-layout + showLabels: true + label: Coordinator + elements: + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/cpu|/spec/verticalScaling/exporter/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/cpu|/spec/verticalScaling/exporter/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/memory|/spec/verticalScaling/exporter/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/memory|/spec/verticalScaling/exporter/resources/limits/memory +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion + elements: + - type: block-layout + label: MSSQLServer + showLabels: true + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/mssqlserver + schema: schema/properties/spec/properties/volumeExpansion/properties/mssqlserver + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-mssqlserveropsrequest-editor/ui/functions.js b/charts/opskubedbcom-mssqlserveropsrequest-editor/ui/functions.js index e26e2f618d..6fe27667ae 100644 --- a/charts/opskubedbcom-mssqlserveropsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-mssqlserveropsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,994 +305,998 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} +let machinesFromPreset = [] -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +export const useFunc = (model) => { + const route = store.state?.route -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + getDbDetails() + showAndInitOpsRequestType() - const resources = (resp && resp.data && resp.data.items) || [] + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mssqlservers`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mssqlservers/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.MSSQLServer?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/mssqlserverversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mssqlservers`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredMSSQLServerVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredMSSQLServerVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mssqlservers/${name}` + const resp = await axios.get(url) - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + setDiscriminatorValue('/dbDetails', resp.data || {}) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.MSSQLServer?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/mssqlserverversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredMSSQLServerVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredMSSQLServerVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (dbType === 'Standalone') return true - else return false - } else return false -} + return selectedType === type + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType() -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + if (dbType === 'Standalone') return true + else return false + } else return false + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function asDatabaseOperation() { + return !!route.params.actions + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return !ver + } -// machine profile stuffs -let machinesFromPreset = [] + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() + return value === verd + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // machine profile stuffs + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const containers = dbDetails?.spec?.podTemplate?.spec?.containers || [] + const mssqlContainer = containers.find((c) => c.name === 'mssql') + const limits = mssqlContainer?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + const text = machineData.name ? machineData.name : machineData.id + return { + text, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + const text = machine + return { + text, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' - - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const containers = dbDetails?.spec?.podTemplate?.spec?.containers || [] + const mssqlContainer = containers.find((c) => c.name === 'mssql') + const limits = mssqlContainer?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + if (obj && Object.keys(obj).length) commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: path, + value: obj, force: true, }) + + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') + else { + annotations['kubernetes.io/instance-type'] = selectedMachine + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + } } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + // watchDependency('discriminator#/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + setDiscriminatorValue('/applyConfig', []) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } + function initTlsOperation() { + return 'update' } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') + commit('wizard/model$delete', '/spec/tls') - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, + }) + } } -} - -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - - return verd -} -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) - - return !hasTls -} + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + return verd + } -// ************************************** Set db details ***************************************** + function isIssuerRefRequired() { + const hasTls = hasTlsField() -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + return !hasTls + } - return !dbDetails || !dbName -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') - const retValue = getValue(discriminator, `/dbDetails${path}`) + return !dbDetails || !dbName + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function setValueFromDbDetails(path, commitPath) { + // watchDependency('discriminator#/dbDetails') + const retValue = getValue(discriminator, `/dbDetails${path}`) - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined } - return retValue || undefined -} - -function setResource({ discriminator, getValue, watchDependency }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const resource = containers.filter((ele) => ele.name === 'mssql') - return resource[0].resources -} + function setResource(path) { + // watchDependency('discriminator#/dbDetails') + const containers = getValue(discriminator, `/dbDetails${path}`) || [] + const resource = containers.filter((ele) => ele.name === 'mssql') + return resource[0]?.resources + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function setApplyToIfReady() { - return 'IfReady' -} + function setApplyToIfReady() { + return 'IfReady' + } -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + function isVerticalScaleTopologyRequired() { + // watchDependency(`discriminator#/topologyKey`) + // watchDependency(`discriminator#/topologyValue`) - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/mssqlserver/topology` + const key = getValue(discriminator, '/topologyKey') + const value = getValue(discriminator, '/topologyValue') + const path = `/spec/verticalScaling/mssqlserver/topology` - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } } -} -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, - } + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') - const value = parseFloat(match[1]) - const unit = match[2] + const value = parseFloat(match[1]) + const unit = match[2] - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - return value * units[unit] -} + return value * units[unit] + } -return { - isRancherManaged, - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + isRancherManaged, + setResource, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + disableOpsRequest, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onNamespaceChange, + onDbChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-mysqlopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-mysqlopsrequest-editor/ui/create-ui.yaml index ced9db5b87..1614e40d6d 100644 --- a/charts/opskubedbcom-mysqlopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-mysqlopsrequest-editor/ui/create-ui.yaml @@ -1,413 +1,492 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|cluster|horizontalScaling - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/member - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|mysql|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mysql/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mysql/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey: - default: "" - type: string - topologyValue: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyKey - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyValue - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - label: - text: labels.mysql - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/mysql - show_label: true - type: single-step-form - - computed: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources|/spec/verticalScaling/exporter/resources - label: - text: labels.exporter - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter/properties/resources - type: resource-input-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mysql - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/mysql - - label: - text: Mode +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: onRequestTypeChange + paths: + - schema/properties/spec/properties/type + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling + elements: + - type: input-compare + label: Replicas + if: + type: function + name: ifDbTypeEqualsTo|cluster|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/member +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: block-layout + label: MySQL vertical scaling + showLabels: false elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|mysql|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/mysql/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/mysql/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/mysql/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue + - type: horizontal-layout + showLabels: true + label: Exporter + # schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources + # init: + # type: func + # value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources|/spec/verticalScaling/exporter/resources + elements: + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/cpu|/spec/verticalScaling/exporter/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/cpu|/spec/verticalScaling/exporter/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/memory|/spec/verticalScaling/exporter/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/memory|/spec/verticalScaling/exporter/resources/limits/memory +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/mysql + schema: schema/properties/spec/properties/volumeExpansion/properties/mysql + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + watcher: + func: onTlsOperationChange + paths: + - temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: requireSSL + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: switch + label: Require SSL + init: + type: func + value: setValueFromDbDetails|/spec/tls/requireSSL + schema: schema/properties/spec/properties/tls/properties/requireSSL + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: setValueFromDbDetails|/spec/tls/requireSSL - label: - text: labels.require_ssl_question - schema: - $ref: schema#/properties/spec/properties/tls/properties/requireSSL - type: switch - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-mysqlopsrequest-editor/ui/functions.js b/charts/opskubedbcom-mysqlopsrequest-editor/ui/functions.js index 064d165e51..b2177d711d 100644 --- a/charts/opskubedbcom-mysqlopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-mysqlopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,1018 +305,1049 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/group') === 'kubedb.com') return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/group') === 'kubedb.com') return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mysqls`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mysqls/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.MySQL?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/mysqlversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mysqls`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - - const isGroupRepl = !!getValue(discriminator, '/dbDetails/spec/topology') - const allowed = isGroupRepl - ? found?.spec?.updateConstraints?.allowlist.groupReplication - : found?.spec?.updateConstraints?.allowlist.standalone - - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredMySQLVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredMySQLVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mysqls/${name}` + const resp = await axios.get(url) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher - } - return 0 // versions are equal -} + setDiscriminatorValue('/dbDetails', resp.data || {}) -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + return resp.data || {} + } else return {} } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return selectedType === type -} + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', - } + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + try { + const presetVersions = presets.admin?.databases?.MySQL?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/mysqlversions`, + { + params: queryParams, + }, + ) - if (dbType === 'standalone') return true - else return false - } else return false -} + const resources = (resp && resp.data && resp.data.items) || [] -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + + if (found) ver = found.spec?.version + + const isGroupRepl = !!getValue(discriminator, '/dbDetails/spec/topology') + const allowed = isGroupRepl + ? found?.spec?.updateConstraints?.allowlist.groupReplication + : found?.spec?.updateConstraints?.allowlist.standalone + + const limit = allowed.length ? allowed[0] : '0.0' + + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredMySQLVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + return filteredMySQLVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - const { spec } = dbDetails || {} - const { topology } = spec || {} - const { mode } = topology || {} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 - if (mode) { - verd = 'cluster' - } else { - verd = 'standalone' + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - return verd -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + return selectedType === type + } -function asDatabaseOperation(route) { - return route.params.actions -} + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType() - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + if (dbType === 'standalone') return true + else return false + } else return false + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const { spec } = dbDetails || {} + return spec?.tls || undefined + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) - } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + const { spec } = dbDetails || {} + const { topology } = spec || {} + const { mode } = topology || {} + + const verd = mode ? 'cluster' : 'standalone' + + return verd } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + function asDatabaseOperation() { + return !!route.params.actions } - return !ver -} + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - return value === verd -} + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) -// machine profile stuffs -let machinesFromPreset = [] + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, }) - .filter((val) => !!val) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + return !ver + } - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + return !ver } - const path = `/spec/verticalScaling/${type}/resources` + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: '/spec/type', + value: opMap[opstype], force: true, }) + } + + return !ver } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) - - const secrets = (resp && resp.data && resp.data.items) || [] + return value === verd + } - const filteredSecrets = secrets + // machine profile stuffs + // let machinesFromPreset = [] + + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } + }) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr + } - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const machine = annotations['kubernetes.io/instance-type'] || 'custom' -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } -} - -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const path = `/spec/verticalScaling/${type}/resources` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') + else { + annotations['kubernetes.io/instance-type'] = selectedMachine + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + } } - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function isMachineCustom() { + // watchDependency('discriminator#/machine') + const machine = getValue(discriminator, '/machine') + return machine === 'custom' + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, + ) + + const secrets = (resp && resp.data && resp.data.items) || [] + + const filteredSecrets = secrets + + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) + return filteredSecrets + } + + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) } - }) -} -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') + return ans + } + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, + }) - return reconfigurationType === value -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - const configObj = {} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + // watchDependency('discriminator#/reconfigurationType') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + return reconfigurationType === value + } + + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') + + const configObj = {} + + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + setDiscriminatorValue('/applyConfig', []) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') + if (apiGroup) return apiGroup + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/remove') + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, + }) + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/rotateCertificates') } } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - commit('wizard/model$delete', '/spec/tls') + return verd + } - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + function isIssuerRefRequired() { + const hasTls = hasTlsField() + + return !hasTls } -} -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } - return verd -} + // ************************************** Set db details ***************************************** -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') - return !hasTls -} + return !dbDetails || !dbName + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function setValueFromDbDetails(path, commitPath) { + // watchDependency('discriminator#/dbDetails') -// ************************************** Set db details ***************************************** + const retValue = getValue(discriminator, `/dbDetails${path}`) -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + if (commitPath && retValue) { + const tlsOperation = getValue(discriminator, '/tlsOperation') - return !dbDetails || !dbName -} + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } - const retValue = getValue(discriminator, `/dbDetails${path}`) + return retValue || undefined + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function setConfigFiles() { + // watchDependency('model#/resources/secret_config/stringData') + const configFiles = getValue(model, '/resources/secret_config/stringData') - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + const files = [] - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + for (const item in configFiles) { + const obj = {} + obj.key = item + obj.value = configFiles[item] + files.push(obj) + } + + return files } - return retValue || undefined -} + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } -function setConfigFiles({ model, getValue, watchDependency }) { - watchDependency('model#/resources/secret_config/stringData') - const configFiles = getValue(model, '/resources/secret_config/stringData') + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - const files = [] + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } - for (const item in configFiles) { - const obj = {} - obj.key = item - obj.value = configFiles[item] - files.push(obj) + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') } - return files -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function isVerticalScaleTopologyRequired() { + // watchDependency('discriminator#/topologyKey') + // watchDependency('discriminator#/topologyValue') -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + const key = getValue(discriminator, '/topologyKey') + const value = getValue(discriminator, '/topologyValue') + const path = `/spec/verticalScaling/mysql/topology` -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function setApplyToIfReady() { - return 'IfReady' -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/mysql/topology` + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false - } -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + const value = parseFloat(match[1]) + const unit = match[2] - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + return value * units[unit] } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } - return value * units[unit] -} + function disableAlias() { + return !!(model && model.alias) + } -return { - isRancherManaged, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isDatabaseRefDisabled, - isNamespaceDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isDatabaseRefDisabled, + isNamespaceDisabled, + onNamespaceChange, + onDbChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + setConfigFiles, + } } diff --git a/charts/opskubedbcom-perconaxtradbopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-perconaxtradbopsrequest-editor/ui/create-ui.yaml index f1a88f9ed7..2d76d0c9a0 100644 --- a/charts/opskubedbcom-perconaxtradbopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-perconaxtradbopsrequest-editor/ui/create-ui.yaml @@ -1,411 +1,455 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - label: - text: Member - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/member - type: input - - computed: setValueFromDbDetails|/spec/replicas - label: - text: labels.memberWeight - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/memberWeight - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|perconaxtradb|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/perconaxtradb/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/perconaxtradb/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey: - default: "" - type: string - topologyValue: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyKey - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyValue - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - label: - text: Perconaxtradb - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/perconaxtradb - show_label: true - type: single-step-form - - computed: setValueFromDbDetails|/spec/coordinator/resources - label: - text: Coordinator - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources - type: resource-input-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/perconaxtradb - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/perconaxtradb - - label: - text: Mode +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + watcher: + func: onNamespaceChange + paths: + - schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/metadata/properties/namespace + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: onRequestTypeChange + paths: + - schema/properties/spec/properties/type + isHorizontal: true + schema: schema/properties/spec/properties/type +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling + elements: + - type: input-compare + label: Member + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/member + - type: input-compare + label: Member Weight + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/memberWeight +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: block-layout + label: Perconaxtradb Vertical Scaling + showLabels: false + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|perconaxtradb|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/perconaxtradb/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/perconaxtradb/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/perconaxtradb/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue + - type: horizontal-layout + showLabels: true + label: Coordinator + elements: + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/coordinator/resources/requests/cpu|/spec/verticalScaling/coordinator/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/coordinator/resources/limits/cpu|/spec/verticalScaling/coordinator/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/coordinator/resources/requests/memory|/spec/verticalScaling/coordinator/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/coordinator/resources/limits/memory|/spec/verticalScaling/coordinator/resources/limits/memory +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/perconaxtradb + schema: schema/properties/spec/properties/volumeExpansion/properties/perconaxtradb + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-perconaxtradbopsrequest-editor/ui/functions.js b/charts/opskubedbcom-perconaxtradbopsrequest-editor/ui/functions.js index 99561c4574..9415eb52d2 100644 --- a/charts/opskubedbcom-perconaxtradbopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-perconaxtradbopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,996 +305,1023 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/perconaxtradbs`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/perconaxtradbs/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.PerconaXtraDB?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/perconaxtradbversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/perconaxtradbs`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredPerconaXtraDBVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredPerconaXtraDBVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/perconaxtradbs/${name}` + const resp = await axios.get(url) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + setDiscriminatorValue('/dbDetails', resp.data || {}) + + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.PerconaXtraDB?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/perconaxtradbversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredPerconaXtraDBVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredPerconaXtraDBVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (dbType === 'Standalone') return true - else return false - } else return false -} + return selectedType === type + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { mode } = spec || {} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } - return mode || 'Standalone' -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + const { mode } = spec || {} -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + return mode || 'Standalone' + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function disableOpsRequest() { + return false + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function asDatabaseOperation() { + return !!route.params.actions + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) + return !ver + } - return value === verd -} + // // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() -// machine profile stuffs -let machinesFromPreset = [] + return value === verd + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // // machine profile stuffs + // let machinesFromPreset = [] + + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' - - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` + + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) + + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + + if (selectedMachine === 'custom') { + // remove the instance-type annotation for custom machines + delete annotations['kubernetes.io/instance-type'] + parsedInstance = {} + } else { + parsedInstance = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + } - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine if (machinesFromPreset.length) commit('wizard/model$update', { path: '/metadata/annotations', value: annotations, force: true, }) + + if (!parsedInstance || (parsedInstance && Object.keys(parsedInstance).length === 0)) + commit('wizard/model$delete', '/metadata/annotations') } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } + + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} - -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + const watchPath = `discriminator#/reconfigurationType` + // watchDependency(watchPath) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const configPath = `/applyConfig` + const applyconfig = getValue(discriminator, configPath) -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: `/spec/configuration/applyConfig`, + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + setDiscriminatorValue(`/applyConfig`, []) + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} - -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - return verd -} - -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + function isIssuerRefRequired() { + const hasTls = hasTlsField() - return !hasTls -} + return !hasTls + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -// ************************************** Set db details ***************************************** + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + return !dbDetails || !dbName + } - return !dbDetails || !dbName -} + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) -function setResource({ discriminator, getValue, watchDependency, storeGet }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0].resources -} + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - const retValue = getValue(discriminator, `/dbDetails${path}`) + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') } - return retValue || undefined -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function isVerticalScaleTopologyRequired() { + // watchDependency(`discriminator#/topologyKey`) + // watchDependency(`discriminator#/topologyValue`) -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + const key = getValue(discriminator, `/topologyKey`) + const value = getValue(discriminator, `/topologyValue`) + const path = `/spec/verticalScaling/perconaxtradb/topology` -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function setApplyToIfReady() { - return 'IfReady' -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/perconaxtradb/topology` + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false - } -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + const value = parseFloat(match[1]) + const unit = match[2] - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + return value * units[unit] } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') - - const value = parseFloat(match[1]) - const unit = match[2] + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } - return value * units[unit] -} + function disableAlias() { + return !!(model && model.alias) + } -return { - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-pgbounceropsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-pgbounceropsrequest-editor/ui/create-ui.yaml index 95eb81e9cf..8d2300ea3c 100644 --- a/charts/opskubedbcom-pgbounceropsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-pgbounceropsrequest-editor/ui/create-ui.yaml @@ -1,296 +1,289 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - label: - text: Replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/replicas - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|pgbouncer|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/pgbouncer/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/pgbouncer/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/pgbouncer/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/pgbouncer/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/pgbouncer/properties/topology - show_label: true - type: single-step-form - label: - text: PgBouncer - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/pgbouncer - show_label: true - type: single-step-form - - elements: - - computed: setResource|/spec/podTemplate/spec/containers - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter/properties/resources - type: resource-input-form - label: - text: Exporter - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: input-compare + label: Replicas + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/replicas +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configuration/pgbouncer/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/pgbouncer/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/pgbouncer/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: block-layout + label: PgBouncer Vertical Scaling + showLabels: true elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/pgbouncer/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|pgbouncer|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/pgbouncer/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/pgbouncer/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/pgbouncer/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue + - type: horizontal-layout + showLabels: true + label: Exporter + # schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources + # init: + # type: func + # value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources|/spec/verticalScaling/exporter/resources + elements: + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/cpu|/spec/verticalScaling/exporter/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/cpu|/spec/verticalScaling/exporter/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/memory|/spec/verticalScaling/exporter/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/memory|/spec/verticalScaling/exporter/resources/limits/memory +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: PgBouncer Configuration + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: PgBouncer config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configuration/pgbouncer/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/pgbouncer/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/pgbouncer/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-pgbounceropsrequest-editor/ui/functions.js b/charts/opskubedbcom-pgbounceropsrequest-editor/ui/functions.js index d2d4f75b26..06d05ea88a 100644 --- a/charts/opskubedbcom-pgbounceropsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-pgbounceropsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,952 +305,963 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgbouncers`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} + } -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + function returnFalse() { + return false + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgbouncers/${name}` - const resp = await axios.get(url) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resp.data || {} - } else return {} -} - -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.PgBouncer?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/pgbouncerversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgbouncers`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredPgBouncerVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredPgBouncerVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgbouncers/${name}` + const resp = await axios.get(url) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + setDiscriminatorValue('/dbDetails', resp.data || {}) + + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.PgBouncer?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/pgbouncerversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredPgBouncerVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredPgBouncerVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (dbType === 'Standalone') return true - else return false - } else return false -} + return selectedType === type + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType({ + discriminator, + getValue, + }) -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + if (dbType === 'Standalone') return true + else return false + } else return false + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function asDatabaseOperation() { + return !!route.params.actions + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return !ver + } -// machine profile stuffs -let machinesFromPreset = [] + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() + return value === verd + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // machine profile stuffs + // let machinesFromPreset = [] + + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let machine = 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + try { + if (instance) machine = instance + } catch (e) { + console.log(e) + machine = 'custom' + } - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + if (obj && Object.keys(obj).length) commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: path, + value: obj, force: true, }) + + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') + else { + annotations['kubernetes.io/instance-type'] = selectedMachine + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + } } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + function isMachineCustom() { + // watchDependency('discriminator#/machine') + const machine = getValue(discriminator, '/machine') + return machine === 'custom' + } + + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } + + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + const watchPath = 'discriminator#/reconfigurationType' + // watchDependency(watchPath) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const configPath = '/applyConfig' + const applyconfig = getValue(discriminator, configPath) + + const configObj = {} -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/pgbouncer/removeCustomConfig`, - value: true, + path: `/spec/configuration/pgbouncer/applyConfig`, + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + setDiscriminatorValue('/applyConfig', []) + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/pgbouncer/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/pgbouncer/configSecret`) + commit('wizard/model$delete', `/spec/configuration/pgbouncer/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/pgbouncer/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} - -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} - -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - - return verd -} - -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) - - return !hasTls -} - -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} -// ************************************** Set db details ***************************************** + function isIssuerRefRequired() { + const hasTls = hasTlsField() -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + return !hasTls + } - return !dbDetails || !dbName -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') - const retValue = getValue(discriminator, `/dbDetails${path}`) + return !dbDetails || !dbName + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + console.log('tlsOperation', tlsOperation) + console.log('commitPath', commitPath) + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + console.log({ retValue }) + return retValue || undefined } - return retValue || undefined -} + function setResource(path) { + const containers = getValue(discriminator, `/dbDetails${path}`) || [] + // for standalone + if (!containers.length) + return getValue(discriminator, '/dbDetails/spec/podTemplate/spec/resources') || {} -function setResource({ discriminator, getValue, watchDependency }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - // for standalone - if (!containers.length) - return getValue(discriminator, '/dbDetails/spec/podTemplate/spec/resources') || {} - - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0].resources -} + const kind = getValue(discriminator, '/dbDetails/kind') + const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) + return resource[0]?.resources || {} + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function setApplyToIfReady() { - return 'IfReady' -} + function setApplyToIfReady() { + return 'IfReady' + } -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + function isVerticalScaleTopologyRequired() { + // watchDependency('discriminator#/topologyKey') + // watchDependency('discriminator#/topologyValue') - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/pgbouncer/topology` + const key = getValue(discriminator, '/topologyKey') + const value = getValue(discriminator, '/topologyValue') + const path = `/spec/verticalScaling/pgbouncer/topology` - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } } -} -return { - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, + return { + fetchAliasOptions: getAliasOptions, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + setResource, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + } } diff --git a/charts/opskubedbcom-pgpoolopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-pgpoolopsrequest-editor/ui/create-ui.yaml index daf9572353..92d09ede14 100644 --- a/charts/opskubedbcom-pgpoolopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-pgpoolopsrequest-editor/ui/create-ui.yaml @@ -1,368 +1,408 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/node - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: onRequestTypeChange + paths: + - schema/properties/spec/properties/type + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|node|/spec/podTemplate/spec/containers - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology - show_label: true - type: single-step-form - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: input-compare + label: Node + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/node +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: block-layout + label: Node Vertical Scaling + showLabels: false + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|node|/spec/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: block-layout + label: Configuration elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + # watcher: + # func: initIssuerRefApiGroup + # paths: + # - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-pgpoolopsrequest-editor/ui/functions.js b/charts/opskubedbcom-pgpoolopsrequest-editor/ui/functions.js index b302f3fcae..40ef613537 100644 --- a/charts/opskubedbcom-pgpoolopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-pgpoolopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,949 +305,987 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} +let machinesFromPreset = [] -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +export const useFunc = (model) => { + const route = store.state?.route -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + getDbDetails() + showAndInitOpsRequestType() - const resources = (resp && resp.data && resp.data.items) || [] + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgpools`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgpools/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.Pgpool?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/pgpoolversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgpools`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredPgpoolVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredPgpoolVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/pgpools/${name}` + const resp = await axios.get(url) - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + setDiscriminatorValue('/dbDetails', resp.data || {}) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.Pgpool?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/pgpoolversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredPgpoolVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredPgpoolVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (dbType === 'Standalone') return true - else return false - } else return false -} + return selectedType === type + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType() -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + if (dbType === 'Standalone') return true + else return false + } else return false + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function asDatabaseOperation() { + return !!route.params.actions + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return !ver + } -// machine profile stuffs -let machinesFromPreset = [] + // vertical scaling + function ifDbTypeEqualsTo(value) { + const verd = getDbType() + return value === verd + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // machine profile stuffs + + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const containers = dbDetails?.spec?.podTemplate?.spec?.containers || [] + const kind = dbDetails?.kind + const resource = containers.filter((ele) => ele.name === kind?.toLowerCase()) + const limits = resource[0]?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} - -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const containers = dbDetails?.spec?.podTemplate?.spec?.containers || [] + const kind = dbDetails?.kind + const resource = containers.filter((ele) => ele.name === kind?.toLowerCase()) + const limits = resource[0]?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` + + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) + + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + if (selectedMachine === 'custom') parsedInstance = {} + else parsedInstance = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine if (machinesFromPreset.length) commit('wizard/model$update', { path: '/metadata/annotations', value: annotations, force: true, }) + + if (!parsedInstance) commit('wizard/model$delete', '/metadata/annotations') } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function isMachineCustom() { + // watchDependency('discriminator#/machine') + const machine = getValue(discriminator, '/machine') + return machine === 'custom' + } + + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + // watchDependency('discriminator#/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + setDiscriminatorValue('/applyConfig', []) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') + if (apiGroup) return apiGroup + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} - -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + function isIssuerRefRequired() { + const hasTls = hasTlsField() - return verd -} + return !hasTls + } -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } - return !hasTls -} + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + return !dbDetails || !dbName + } -// ************************************** Set db details ***************************************** + function setValueFromDbDetails(path, commitPath) { + // watchDependency('discriminator#/dbDetails') -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + const retValue = getValue(discriminator, `/dbDetails${path}`) - return !dbDetails || !dbName -} + if (commitPath && retValue) { + const tlsOperation = getValue(discriminator, '/tlsOperation') -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - const retValue = getValue(discriminator, `/dbDetails${path}`) + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + return retValue || undefined + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace } - return retValue || undefined -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -function setResource({ discriminator, getValue, watchDependency, storeGet }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0].resources -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function setApplyToIfReady() { + return 'IfReady' + } -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + function isVerticalScaleTopologyRequired() { + // watchDependency('discriminator#/topologyKey') + // watchDependency('discriminator#/topologyValue') -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + const key = getValue(discriminator, '/topologyKey') + const value = getValue(discriminator, '/topologyValue') + const path = `/spec/verticalScaling/node/topology` -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } + } -function setApplyToIfReady() { - return 'IfReady' -} + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/pgpool/topology` + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + function disableAlias() { + return !!(model && model.alias) } -} -return { - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + initNamespace, + initDatabaseRef, + isRancherManaged, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + disableOpsRequest, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onNamespaceChange, + onDbChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + } } diff --git a/charts/opskubedbcom-postgresopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-postgresopsrequest-editor/ui/create-ui.yaml index 01bcc23a63..8ad38595b6 100644 --- a/charts/opskubedbcom-postgresopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-postgresopsrequest-editor/ui/create-ui.yaml @@ -1,435 +1,502 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|cluster|horizontalScaling - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/replicas - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - elements: - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|postgres|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/postgres/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling + elements: + - type: input-compare + label: Replicas + if: + type: function + name: ifDbTypeEqualsTo|cluster|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/replicas +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: block-layout + label: Postgres Vertical Scaling + showLabels: false + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|postgres|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/postgres/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/postgres/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/postgres/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue + - type: horizontal-layout + showLabels: true + label: Exporter + # schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources + # init: + # type: func + # value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources|/spec/verticalScaling/exporter/resources + elements: + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/cpu|/spec/verticalScaling/exporter/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/cpu|/spec/verticalScaling/exporter/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/memory|/spec/verticalScaling/exporter/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/memory|/spec/verticalScaling/exporter/resources/limits/memory +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/postgres + schema: schema/properties/spec/properties/volumeExpansion/properties/postgres + - type: select + label: Mode options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/postgres/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey: - default: "" - type: string - topologyValue: - default: "" - type: string + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration + showLabels: true elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyKey - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyValue - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - label: - text: labels.postgres - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/postgres - show_label: true - type: single-step-form - - computed: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources|/spec/verticalScaling/exporter/resources - label: - text: labels.exporter - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter/properties/resources - type: resource-input-form - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/postgres - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/postgres - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/postgres - - label: - text: Mode - options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: radio + label: Client Auth Mode + init: + type: func + value: setClientAuthMode + loader: getClientAuthModes + schema: schema/properties/spec/properties/tls/properties/clientAuthMode + - type: block-layout + label: SSL Mode + showLabels: false + if: + name: showIssuerRefAndCertificates + type: function elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: radio + label: SSL Mode + init: + type: func + value: setSSLMode + options: + - text: allow + value: allow + - text: prefer + value: prefer + - text: require + value: require + - text: verify-ca + value: verify-ca + - text: verify-full + value: verify-full + schema: schema/properties/spec/properties/tls/properties/sslMode + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - computed: setClientAuthMode - fetch: getClientAuthModes - label: - text: labels.client_auth_mode - schema: - $ref: schema#/properties/spec/properties/tls/properties/clientAuthMode - type: radio - - elements: - - computed: setSSLMode - label: - text: labels.ssl_mode - options: - - text: allow - value: allow - - text: prefer - value: prefer - - text: require - value: require - - text: verify-ca - value: verify-ca - - text: verify-full - value: verify-full - schema: - $ref: schema#/properties/spec/properties/tls/properties/sslMode - type: radio - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always \ No newline at end of file diff --git a/charts/opskubedbcom-postgresopsrequest-editor/ui/functions.js b/charts/opskubedbcom-postgresopsrequest-editor/ui/functions.js index 5879ff2c53..4a5d0bc433 100644 --- a/charts/opskubedbcom-postgresopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-postgresopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,1035 +305,1106 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} +let machinesFromPreset = [] -function returnFalse() { - return false -} +export const useFunc = (model) => { + const route = store.state?.route -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + getDbDetails() + showAndInitOpsRequestType() - const resources = (resp && resp.data && resp.data.items) || [] + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/postgreses`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/postgreses/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.Postgres?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/postgresversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/postgreses`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredPostgresVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredPostgresVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/postgreses/${name}` + const resp = await axios.get(url) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher - } - return 0 // versions are equal -} + setDiscriminatorValue('/dbDetails', resp.data || {}) -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + return resp.data || {} + } else return {} } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.Postgres?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/postgresversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredPostgresVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredPostgresVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } + } - return selectedType === type -} -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', - } - - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const postgresDetails = getValue(discriminator, '/dbDetails') + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } - const { spec } = postgresDetails || {} - const { standbyMode } = spec || {} + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (standbyMode) { - verd = 'cluster' - } else { - verd = 'standalone' + return selectedType === type } - return verd -} + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) }) + } - if (dbType === 'standalone') return true - else return false - } else return false -} - -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const postgresDetails = getValue(discriminator, '/dbDetails') -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + const { spec } = postgresDetails || {} + const { standbyMode } = spec || {} + let verd = '' - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + if (standbyMode) { + verd = 'cluster' + } else { + verd = 'standalone' + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + return verd + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType() -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + if (dbType === 'standalone') return true + else return false + } else return false + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function asDatabaseOperation() { + return !!route.params.actions } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', - } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) + return !ver + } - return value === verd -} + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } -// machine profile stuffs -let machinesFromPreset = [] + return !ver + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() + } + + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, }) - .filter((val) => !!val) + } + + return !ver } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() + return value === verd + } - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + // machine profile stuffs + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } + }) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr + } - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let machine = 'custom' + try { + if (instance) machine = JSON.parse(instance) || 'custom' + } catch (e) { + console.log(e) + machine = 'custom' + } -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return { machine } + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` + + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) + + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') delete annotations['kubernetes.io/instance-type'] + else annotations['kubernetes.io/instance-type'] = selectedMachine - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine if (machinesFromPreset.length) commit('wizard/model$update', { path: '/metadata/annotations', value: annotations, force: true, }) + + if (annotations && Object.keys(annotations).length === 0) + commit('wizard/model$delete', '/metadata/annotations') } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - - return reconfigurationType === value -} - -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') - - const configObj = {} - - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + const watchPath = `discriminator#/reconfigurationType` + // watchDependency(watchPath) + return reconfigurationType === value + } + + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + setDiscriminatorValue('/applyConfig', []) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function setSSLMode({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') + // for tls + function hasTlsField() { + const tls = getDbTls() + return !!tls + } - const retValue = getValue(discriminator, `/dbDetails/spec/sslMode`) - return retValue || 'require' -} + function setSSLMode() { + // watchDependency('discriminator#/dbDetails') + const retValue = getValue(discriminator, `/dbDetails/spec/sslMode`) + return retValue || 'require' + } -function setClientAuthMode({ discriminator, getValue, watchDependency, commit }) { - watchDependency('discriminator#/dbDetails') + function setClientAuthMode() { + // watchDependency('discriminator#/dbDetails') + const retValue = getValue(discriminator, `/dbDetails/spec/clientAuthMode`) - const retValue = getValue(discriminator, `/dbDetails/spec/clientAuthMode`) + commit('wizard/model$update', { + path: '/spec/tls/clientAuthMode', + value: retValue || '', + force: true, + }) - commit('wizard/model$update', { - path: '/spec/tls/clientAuthMode', - value: retValue || '', - force: true, - }) + return retValue + } - return retValue -} + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') -function initIssuerRefApiGroup({ getValue, model, watchDependency }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + if (kind) { + return 'cert-manager.io' + } else return undefined + } - if (kind) { - return 'cert-manager.io' - } else return undefined -} + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - commit('wizard/model$delete', '/spec/tls') + return verd + } - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) + function isIssuerRefRequired() { + const hasTls = hasTlsField() + return !hasTls } -} -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + function getClientAuthModes() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - return verd -} + const { spec } = dbDetails || {} + const { version } = spec || {} -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + // watchDependency('discriminator#/tlsOperation') + const tlsOperation = getValue(discriminator, '/tlsOperation') - return !hasTls -} + // major version section from version + const major = parseInt(version && version.split('.')[0]) -function getClientAuthModes({ getValue, watchDependency, discriminator }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + const options = ['md5'] - const { spec } = dbDetails || {} - const { version } = spec || {} + if (major >= 11) { + options.push('scram') + } - watchDependency('discriminator#/tlsOperation') + if (tlsOperation !== 'remove') { + options.push('cert') + } - const tlsOperation = getValue(discriminator, '/tlsOperation') + return options.map((item) => ({ text: item, value: item })) + } - // major version section from version - const major = parseInt(version && version.split('.')[0]) + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } - const options = ['md5'] + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') - if (major >= 11) { - options.push('scram') + return !dbDetails || !dbName } - if (tlsOperation !== 'remove') { - options.push('cert') + function setValueFromDbDetails(path, commitPath) { + // watchDependency('discriminator#/dbDetails') + const retValue = getValue(discriminator, `/dbDetails${path}`) + + if (commitPath && retValue) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + + return retValue || undefined } - return options.map((item) => ({ text: item, value: item })) -} + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } - return !dbDetails || !dbName -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') - const retValue = getValue(discriminator, `/dbDetails${path}`) + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function setApplyToIfReady() { + return 'IfReady' + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isVerticalScaleTopologyRequired() { + // watchDependency(`discriminator#/topologyKey`) + // watchDependency(`discriminator#/topologyValue`) - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + const key = getValue(discriminator, `/topologyKey`) + const value = getValue(discriminator, `/topologyValue`) + const path = `/spec/verticalScaling/postgres/topology` + + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } } - return retValue || undefined -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + const value = parseFloat(match[1]) + const unit = match[2] -function setApplyToIfReady() { - return 'IfReady' -} + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + return value * units[unit] + } - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/postgres/topology` + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] + + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } + + function disableAlias() { + return !!(model && model.alias) } -} -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function namespaceWatcherFunctions() { + getDbs() + initDatabaseRef() + getConfigSecrets() + resourceNames() + getIssuerRefsName() + onNamespaceChange() + } - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + function requestTypeWatcherFunctions() { + onRequestTypeChange() + ifRequestTypeEqualsTo() + showAndInitName() + } - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + function databaseRefWatcherFunctions() { + onDbChange() + showAndInitName() + isDbDetailsLoading() } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, - } - - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') - - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - - return value * units[unit] -} + function IssuerRefWatcherFunctions() { + initIssuerRefApiGroup() + getIssuerRefsName() + } -return { - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - setSSLMode, - setClientAuthMode, - getDbType, - disableOpsRequest, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getClientAuthModes, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isDatabaseRefDisabled, - isNamespaceDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + function tlsOperationWatcherFunction() { + showIssuerRefAndCertificates() + onTlsOperationChange() + } + + function dbDetailsWatcherFunction() { + getDbTls() + getDbType() + isDbDetailsLoading() + } + + return { + dbDetailsWatcherFunction, + tlsOperationWatcherFunction, + namespaceWatcherFunctions, + requestTypeWatcherFunctions, + databaseRefWatcherFunctions, + IssuerRefWatcherFunctions, + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + setSSLMode, + setClientAuthMode, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getClientAuthModes, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-proxysqlopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-proxysqlopsrequest-editor/ui/create-ui.yaml index 7cec81be72..4f88f54e50 100644 --- a/charts/opskubedbcom-proxysqlopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-proxysqlopsrequest-editor/ui/create-ui.yaml @@ -1,560 +1,450 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/proxyRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/member - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - schema: - $ref: schema#/properties/spec/properties/horizontalScaling - type: single-step-form - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|proxysql|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/proxysql/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/proxyRef/properties/name + schema: schema/properties/spec/properties/proxyRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/proxysql/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey: - default: "" - type: string - topologyValue: - default: "" - type: string + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/proxyRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyKey - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyValue - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - label: - text: labels.proxysql - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/proxysql - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/initConfig/adminVariables|/spec/configuration/adminVariables - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.configuration.adminVariables - schema: - $ref: schema#/properties/spec/properties/configuration/properties/adminVariables - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/configuration/properties/adminVariables - type: input - - computed: setValueFromDbDetails|/spec/initConfig/mysqlVariables|/spec/configuration/mysqlVariables - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.configuration.mysqlVariables - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlVariables - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlVariables - type: input - - elements: - - label: - text: labels.configuration.reqType - onChange: onMySQLUserReqTypeChange - options: - - add - - update - - delete - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlQueryRules/properties/reqType - type: select - - addFormLabel: labels.configuration.queryRule - computed: setMySQLRules - element: - discriminator: - mysqlQueryRules: - emitAs: mysqlQueryRules - type: array + - type: input-compare + label: Replicas + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/member +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|proxysql|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/proxysql/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/proxysql/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/proxysql/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true elements: - - isArray: true - keys: - label: - text: labels.annotations.key - label: - text: labels.configuration.rules - schema: - $ref: discriminator#/properties/mysqlQueryRules/items/properties/rules - type: key-value-input-form - values: - label: - text: labels.annotations.value - schema: - $ref: discriminator#/properties/mysqlQueryRules/items/properties/rules/additionalProperties - type: input - schema: - $ref: discriminator#/properties/mysqlQueryRules/items - type: single-step-form - label: - text: labels.configuration.queryRules - onChange: onMySQLRulesChange - schema: - $ref: discriminator#/properties/mysqlQueryRules - tableContents: - - inTableColumn: true - label: - text: labels.configuration.rules - path: rules - type: value - typeOfValue: key-value - type: single-step-form-array - label: - text: labels.configuration.mysqlQueryRules - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlQueryRules - show_label: true - type: single-step-form - - customClass: mt-10 + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function elements: - - label: - text: labels.configuration.reqType - onChange: onMySQLUserReqTypeChange - options: - - add - - update - - delete - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/reqType - type: select - - addFormLabel: labels.configuration.user - customClass: mt-20 - element: + - type: input-compare + label: Admin Variables + init: + type: func + value: setValueFromDbDetails|/spec/initConfig/adminVariables|/spec/configuration/adminVariables + schema: schema/properties/spec/properties/configuration/properties/adminVariables + - type: input-compare + label: MySQL Variables + init: + type: func + value: setValueFromDbDetails|/spec/initConfig/mysqlVariables|/spec/configuration/mysqlVariables + schema: schema/properties/spec/properties/configuration/properties/mysqlVariables + - type: block-layout + label: MySQL Query Rules + showLabels: true elements: - - label: - text: labels.configuration.username - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/username - type: input - - label: - text: labels.configuration.active - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/active - type: input - - label: - text: labels.configuration.default_schema - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/default_schema - type: input - - label: - text: labels.configuration.use_ssl - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/use_ssl - type: input - - label: - text: labels.configuration.attributes - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/attributes - type: input - - label: - text: labels.configuration.backend - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/backend - type: input - - label: - text: labels.configuration.comment - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/comment - type: input - - label: - text: labels.configuration.default_hostgroup - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/default_hostgroup - type: input - - label: - text: labels.configuration.fast_forward - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/fast_forward - type: input - - label: - text: labels.configuration.frontend - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/frontend - type: input - - label: - text: labels.configuration.max_connections - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/max_connections - type: input - - label: - text: labels.configuration.schema_locked - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/schema_locked - type: input - - label: - text: labels.configuration.transaction_persistent - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/transaction_persistent - type: input - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items - type: single-step-form - if: showUserCreationField - label: - text: labels.configuration.users - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users - tableContents: - - inTableColumn: true - label: - text: labels.configuration.username - path: username - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.configuration.active - path: active - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.configuration.default_schema - path: default_schema - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.configuration.use_ssl - path: use_ssl - type: value - typeOfValue: string - - label: - text: labels.configuration.attributes - path: attributes - type: value - typeOfValue: string - - label: - text: labels.configuration.backend - path: backend - type: value - typeOfValue: string - - label: - text: labels.configuration.comment - path: comment - type: value - typeOfValue: string - - label: - text: labels.configuration.default_hostgroup - path: default_hostgroup - type: value - typeOfValue: string - - label: - text: labels.configuration.fast_forward - path: fast_forward - type: value - typeOfValue: string - - label: - text: labels.configuration.frontend - path: frontend - type: value - typeOfValue: string - - label: - text: labels.configuration.max_connections - path: max_connections - type: value - typeOfValue: string - - label: - text: labels.configuration.schema_locked - path: schema_locked - type: value - typeOfValue: string - - label: - text: labels.configuration.transaction_persistent - path: transaction_persistent - type: value - typeOfValue: string - type: single-step-form-array - - addFormLabel: labels.configuration.user - customClass: mt-20 - element: + - type: select + label: Request Type + options: + - text: Add + value: add + - text: Update + value: update + - text: Delete + value: delete + watcher: + func: onMySQLUserReqTypeChange + paths: + - schema/properties/spec/properties/configuration/properties/mysqlQueryRules/properties/reqType + schema: schema/properties/spec/properties/configuration/properties/mysqlQueryRules/properties/reqType + - type: array-item-form + label: Query Rules + init: + type: func + value: setMySQLRules + watcher: + func: onMySQLRulesChange + paths: + - temp/mysqlQueryRules + schema: temp/mysqlQueryRules + element: + type: input + label: Rules + schema: items/properties/rules + - type: block-layout + label: MySQL Users + showLabels: true elements: - - label: - text: labels.configuration.username - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items/properties/username - type: input - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users/items - type: single-step-form - if: showUserDeletionField - label: - text: labels.configuration.users - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers/properties/users - tableContents: - - inTableColumn: true - label: - text: labels.configuration.username - path: username - type: value - typeOfValue: string - type: single-step-form-array - label: - text: labels.configuration.mysqlUsers - schema: - $ref: schema#/properties/spec/properties/configuration/properties/mysqlUsers - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - schema: - $ref: schema#/properties/spec/properties/configuration - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: select + label: Request Type + options: + - text: Add + value: add + - text: Update + value: update + - text: Delete + value: delete + watcher: + func: onMySQLUserReqTypeChange + paths: + - schema/properties/spec/properties/configuration/properties/mysqlUsers/properties/reqType + schema: schema/properties/spec/properties/configuration/properties/mysqlUsers/properties/reqType + - type: array-object-form + label: Users + if: + name: showUserCreationField + type: function + schema: schema/properties/spec/properties/configuration/properties/mysqlUsers/properties/users + elements: + - type: input + label: Username + validation: + type: required + schema: items/properties/username + - type: input + label: Active + schema: items/properties/active + - type: input + label: Default Schema + schema: items/properties/default_schema + - type: input + label: Use SSL + schema: items/properties/use_ssl + - type: input + label: Attributes + schema: items/properties/attributes + - type: input + label: Backend + schema: items/properties/backend + - type: input + label: Comment + schema: items/properties/comment + - type: input + label: Default Hostgroup + schema: items/properties/default_hostgroup + - type: input + label: Fast Forward + schema: items/properties/fast_forward + - type: input + label: Frontend + schema: items/properties/frontend + - type: input + label: Max Connections + schema: items/properties/max_connections + - type: input + label: Schema Locked + schema: items/properties/schema_locked + - type: input + label: Transaction Persistent + schema: items/properties/transaction_persistent + - type: array-item-form + label: Users + if: + name: showUserDeletionField + type: function + schema: schema/properties/spec/properties/configuration/properties/mysqlUsers/properties/users + element: + type: input + label: Username + validation: + type: required + schema: items/properties/username +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - customClass: mt-10 - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-proxysqlopsrequest-editor/ui/functions.js b/charts/opskubedbcom-proxysqlopsrequest-editor/ui/functions.js index b2790d8b93..52dcb9744b 100644 --- a/charts/opskubedbcom-proxysqlopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-proxysqlopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,981 +305,955 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/proxysqls`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - const name = getValue(model, '/spec/proxyRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/proxysqls/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.ProxySQL?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/proxysqlversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/proxysqls`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredProxySQLVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredProxySQLVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/proxyRef/name') + + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/proxysqls/${name}` + const resp = await axios.get(url) - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + setDiscriminatorValue('/dbDetails', resp.data || {}) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.ProxySQL?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/proxysqlversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredProxySQLVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredProxySQLVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} - -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } - if (dbType === 'standalone') return true - else return false - } else return false -} + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + return selectedType === type + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } - const { spec } = dbDetails || {} - const { replicas } = spec || {} - let verd = '' + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - if (replicas > 1) { - verd = 'cluster' - } else { - verd = 'standalone' + const { spec } = dbDetails || {} + return spec?.tls || undefined } - return verd -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + const { replicas } = spec || {} + let verd = '' -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + if (replicas > 1) { + verd = 'cluster' + } else { + verd = 'standalone' + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + return verd + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function asDatabaseOperation() { + return !!route.params.actions + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/proxyRef/name') -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) - } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/proxyRef/name', - value: `${route.params.name}`, - force: true, - }) - } + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/proxyRef/name') + const ver = asDatabaseOperation() - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', - } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }, - ) + return !ver + } - const secrets = (resp && resp.data && resp.data.items) || [] + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/proxyRef/name', + value: `${route.params.name}`, + force: true, + }) + } - const filteredSecrets = secrets + return !ver + } - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() + } -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + return !ver + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + // machine profile stuffs + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } + }) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr + } - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const machine = annotations['kubernetes.io/instance-type'] || 'custom' + + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + const path = `/spec/verticalScaling/${type}/resources` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') + else { + annotations['kubernetes.io/instance-type'] = selectedMachine + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + } } - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) + function isMachineCustom() { + // watchDependency('discriminator#/machine') + const machine = getValue(discriminator, '/machine') + return machine === 'custom' } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) - }) - } + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }, + ) -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') + const secrets = (resp && resp.data && resp.data.items) || [] - return reconfigurationType === value -} -function onReconfigurationTypeChange({ commit, discriminator, getValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const filteredSecrets = secrets - commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, - force: true, + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/inlineConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + return filteredSecrets } -} -function disableReconfigurationType({ getValue, watchDependency, discriminator, itemCtx }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - - const { spec } = dbDetails || {} - if (itemCtx.value === 'inlineConfig' || itemCtx.value === 'remove') { - if (spec.configSecret) return false - else return true - } else return false -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return !!tls -} + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` - - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } - } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers - } + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - async function getIssuer(url) { + let ans = [] try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }) - return resources + + const items = (resp && resp.data && resp.data.items) || [] + ans = items } catch (e) { console.log(e) - return [] } - } -} - -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') - - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return ans } -} + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - return verd -} + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - return !hasTls -} + return ans + } + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, + }) -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ - discriminator, - model, - getValue, - watchDependency, - }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } -// ************************************** Set db details ***************************************** + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/proxyRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/proxyRef/name') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - return !dbDetails || !dbName -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + // MySQL Query Rules + function setMySQLRules() { + const rules = getValue(model, '/spec/configuration/mysqlQueryRules/rules') + const modifiedRules = rules?.map((item) => ({ rules: item })) - const retValue = getValue(discriminator, `/dbDetails${path}`) + setDiscriminatorValue('/mysqlQueryRules', modifiedRules) - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + return modifiedRules + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function onMySQLRulesChange() { + const rules = getValue(discriminator, '/mysqlQueryRules') + const modifiedRules = rules?.map((item) => item.rules) - // direct model update required for reusable element. - // computed property is not applicable for reusable element commit('wizard/model$update', { - path: commitPath, - value: retValue, + path: '/spec/configuration/mysqlQueryRules/rules', + value: modifiedRules, force: true, }) } - return retValue || undefined -} + // MySQL Users + function onMySQLUserReqTypeChange() { + const reqType = getValue(model, '/spec/configuration/mysqlUsers/reqType') -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} - -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + if (reqType === 'delete') { + const users = getValue(model, '/spec/configuration/mysqlUsers/users') || [] + const mappedUsers = users.map((item) => { + return { + username: item.username, + } + }) -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + if (mappedUsers && mappedUsers.length) { + commit('wizard/model$update', { + path: '/spec/configuration/mysqlUsers/users', + value: mappedUsers, + force: true, + }) + } + } + } -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + function showUserCreationField() { + // watchDependency('model#/spec/configuration/mysqlUsers/reqType') + const reqType = getValue(model, '/spec/configuration/mysqlUsers/reqType') + return !reqType || reqType === 'update' || reqType === 'add' + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function showUserDeletionField() { + // watchDependency('model#/spec/configuration/mysqlUsers/reqType') + const reqType = getValue(model, '/spec/configuration/mysqlUsers/reqType') + return reqType === 'delete' + } -/**************************************** MySQL Query Rules *******************************/ + // for tls + function hasTlsField() { + const tls = getDbTls() -function onMySQLRulesChange({ discriminator, getValue, commit }) { - const rules = getValue(discriminator, '/mysqlQueryRules') - const modifiedRules = rules?.map((item) => item.rules) + return !!tls + } - commit('wizard/model$update', { - path: '/spec/configuration/mysqlQueryRules/rules', - value: modifiedRules, - force: true, - }) -} + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') -function setMySQLRules({ model, getValue, setDiscriminatorValue }) { - const rules = getValue(model, '/spec/configuration/mysqlQueryRules/rules') - const modifiedRules = rules?.map((item) => ({ rules: item })) + if (kind) { + return 'cert-manager.io' + } else return undefined + } - setDiscriminatorValue('/mysqlQueryRules', modifiedRules) + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') - return modifiedRules -} + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } -/**************************************** MySQL Users *******************************/ + async function getIssuer(url) { + try { + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } + } -function onMySQLUserReqTypeChange({ model, getValue, commit }) { - const reqType = getValue(model, '/spec/configuration/mysqlUsers/reqType') + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - if (reqType === 'delete') { - const users = getValue(model, '/spec/configuration/mysqlUsers/users') || [] - const mappedUsers = users.map((item) => { - return { - username: item.username, - } - }) + commit('wizard/model$delete', '/spec/tls') - if (mappedUsers && mappedUsers.length) { + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { commit('wizard/model$update', { - path: '/spec/configuration/mysqlUsers/users', - value: mappedUsers, + path: '/spec/tls/remove', + value: true, force: true, }) } } -} -function showUserCreationField({ model, getValue, watchDependency }) { - watchDependency('model#/spec/configuration/mysqlUsers/reqType') - const reqType = getValue(model, '/spec/configuration/mysqlUsers/reqType') - return !reqType || reqType === 'update' || reqType === 'add' -} + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' -function showUserDeletionField({ model, getValue, watchDependency }) { - watchDependency('model#/spec/configuration/mysqlUsers/reqType') - const reqType = getValue(model, '/spec/configuration/mysqlUsers/reqType') - return reqType === 'delete' -} + return verd + } -function setApplyToIfReady() { - return 'IfReady' -} + function isIssuerRefRequired() { + const hasTls = hasTlsField() -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + return !hasTls + } - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/proxysql/topology` + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/proxyRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/proxyRef/name') + + return !dbDetails || !dbName } -} -// machine profile stuffs -let machinesFromPreset = [] + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, }) - .filter((val) => !!val) + } + return retValue || undefined } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') } - const path = `/spec/verticalScaling/${type}/resources` + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + function setApplyToIfReady() { + return 'IfReady' + } - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + function isVerticalScaleTopologyRequired() { + // watchDependency('discriminator#/topologyKey') + // watchDependency('discriminator#/topologyValue') + + const key = getValue(discriminator, '/topologyKey') + const value = getValue(discriminator, '/topologyValue') + const path = `/spec/verticalScaling/proxysql/topology` + + if (key || value) { commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: path, + value: { key, value }, force: true, }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } + + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] + + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } + + function disableAlias() { + return !!(model && model.alias) + } -return { - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - getConfigSecrets, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - disableReconfigurationType, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setMySQLRules, - onMySQLRulesChange, - onMySQLUserReqTypeChange, - showUserCreationField, - showUserDeletionField, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - - getMachines, - setMachine, - onMachineChange, - isMachineCustom, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + setMySQLRules, + onMySQLRulesChange, + onMySQLUserReqTypeChange, + showUserCreationField, + showUserDeletionField, + } } diff --git a/charts/opskubedbcom-rabbitmqopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-rabbitmqopsrequest-editor/ui/create-ui.yaml index e61308cc33..78708edb15 100644 --- a/charts/opskubedbcom-rabbitmqopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-rabbitmqopsrequest-editor/ui/create-ui.yaml @@ -1,403 +1,445 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|Combined|horizontalScaling - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/node - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|node|/spec/podTemplate/spec/containers - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology - show_label: true - type: single-step-form - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/node - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/volumeExpansion - show_label: true - type: single-step-form - - label: - text: Mode +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + schema: schema/properties/spec/properties/databaseRef/properties/name + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling + elements: + - type: input-compare + label: Node + if: + type: function + name: ifDbTypeEqualsTo|Combined|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/node +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: block-layout + label: Node + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|node|/spec/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: block-layout + label: Node + showLabels: true elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node + schema: schema/properties/spec/properties/volumeExpansion/properties/node + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function + elements: + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-rabbitmqopsrequest-editor/ui/functions.js b/charts/opskubedbcom-rabbitmqopsrequest-editor/ui/functions.js index bdf6692fa2..65f0a023eb 100644 --- a/charts/opskubedbcom-rabbitmqopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-rabbitmqopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,994 +305,1013 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} +let machinesFromPreset = [] -function returnFalse() { - return false -} +export const useFunc = (model) => { + const route = store.state?.route -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + getDbDetails() + showAndInitOpsRequestType() - const resources = (resp && resp.data && resp.data.items) || [] + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/rabbitmqs`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/rabbitmqs/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resp.data || {} - } else return {} -} + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resources = (resp && resp.data && resp.data.items) || [] - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found } - try { - const presetVersions = presets.admin?.databases?.RabbitMQ?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/rabbitmqversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/rabbitmqs`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredRabbitMQVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredRabbitMQVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/rabbitmqs/${name}` + const resp = await axios.get(url) - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + setDiscriminatorValue('/dbDetails', resp.data || {}) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + + try { + const presetVersions = presets.admin?.databases?.RabbitMQ?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/rabbitmqversions`, + { + params: queryParams, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + + const filteredRabbitMQVersions = sortedVersions.filter((item) => { + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + + return filteredRabbitMQVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 + if (num1 < num2) return -1 + } + return 0 } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (dbType === 'Standalone') return true - else return false - } else return false -} + return selectedType === type + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType() -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + if (dbType === 'Standalone') return true + else return false + } else return false + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function asDatabaseOperation(route) { - return !!route.params.actions -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function asDatabaseOperation() { + return !!route.params.actions + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return !ver + } -// machine profile stuffs -let machinesFromPreset = [] + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() + return value === verd + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const containers = dbDetails?.spec?.podTemplate?.spec?.containers || [] + const kind = dbDetails?.kind || 'RabbitMQ' + const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) + const limits = resource[0]?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + const text = machineData.name ? machineData.name : machineData.id + return { + text, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + const text = machine + return { + text, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const containers = dbDetails?.spec?.podTemplate?.spec?.containers || [] + const kind = dbDetails?.kind || 'RabbitMQ' + const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) + const limits = resource[0]?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const machine = annotations['kubernetes.io/instance-type'] || 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} - -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return { machine, cpu: limits.cpu, memory: limits.memory } + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + if (obj && Object.keys(obj).length) commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: path, + value: obj, force: true, }) + + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') + else { + annotations['kubernetes.io/instance-type'] = selectedMachine + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + } } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function isMachineCustom() { + // watchDependency('discriminator#/machine') + const machine = getValue(discriminator, '/machine') + return machine === 'custom' + } -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + // watchDependency('discriminator#/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + setDiscriminatorValue('/applyConfig', []) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + function hasTlsField() { + const tls = getDbTls() + return !!tls + } - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + if (kind) { + const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') + if (apiGroup) return apiGroup + return 'cert-manager.io' + } else return undefined + } - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/remove') + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, + }) + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/rotateCertificates') } } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - commit('wizard/model$delete', '/spec/tls') + return verd + } - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + function isIssuerRefRequired() { + const hasTls = hasTlsField() + return !hasTls } -} -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } - return verd -} + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + return !dbDetails || !dbName + } - return !hasTls -} + function setValueFromDbDetails(path, commitPath) { + // watchDependency('discriminator#/dbDetails') -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + const retValue = getValue(discriminator, `/dbDetails${path}`) -// ************************************** Set db details ***************************************** + if (commitPath && retValue) { + const tlsOperation = getValue(discriminator, '/tlsOperation') -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - return !dbDetails || !dbName -} + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + return retValue || undefined + } - const retValue = getValue(discriminator, `/dbDetails${path}`) + function setResource(path) { + // watchDependency('discriminator#/dbDetails') + const containers = getValue(discriminator, `/dbDetails${path}`) || [] + const kind = getValue(discriminator, '/dbDetails/kind') + const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) + return resource[0].resources + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name } - return retValue || undefined -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function setResource({ discriminator, getValue, watchDependency, storeGet }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0].resources -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function isVerticalScaleTopologyRequired() { + // watchDependency('discriminator#/topologyKey') + // watchDependency('discriminator#/topologyValue') -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + const key = getValue(discriminator, '/topologyKey') + const value = getValue(discriminator, '/topologyValue') + const path = `/spec/verticalScaling/node/topology` -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function setApplyToIfReady() { - return 'IfReady' -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/rabbitmq/topology` + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false - } -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + const value = parseFloat(match[1]) + const unit = match[2] - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + return value * units[unit] } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } - return value * units[unit] -} + function disableAlias() { + return !!(model && model.alias) + } -return { - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + setResource, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + initNamespace, + initDatabaseRef, + isRancherManaged, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + disableOpsRequest, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onNamespaceChange, + onDbChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-redisopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-redisopsrequest-editor/ui/create-ui.yaml index a65ea9df60..0cd9db3870 100644 --- a/charts/opskubedbcom-redisopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-redisopsrequest-editor/ui/create-ui.yaml @@ -1,416 +1,479 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/cluster/master - if: ifDbTypeEqualsTo|Cluster|horizontalScaling - label: - text: labels.master - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/shards - type: input - - computed: setReplicas - if: ifDbTypeEqualsTo|[Cluster,Sentinel]|horizontalScaling - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/replicas - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|redis|/spec/podTemplate/spec/resources - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/redis/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/redis/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey: - default: "" - type: string - topologyValue: - default: "" - type: string - elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyKey - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyValue - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - label: - text: labels.redis - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/redis - show_label: true - type: single-step-form - - computed: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources|/spec/verticalScaling/exporter/resources - label: - text: labels.exporter - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/exporter/properties/resources - type: resource-input-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/redis - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/redis - - label: - text: Mode +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion + elements: + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling + elements: + - type: input-compare + label: Master + if: + type: function + name: ifDbTypeEqualsTo|Cluster|horizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/cluster/master + schema: schema/properties/spec/properties/horizontalScaling/properties/shards + - type: input-compare + label: Replicas + if: + type: function + name: ifDbTypeEqualsTo|[Cluster,Sentinel]|horizontalScaling + init: + type: func + value: setReplicas + schema: schema/properties/spec/properties/horizontalScaling/properties/replicas +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling + elements: + - type: block-layout + label: Redis + showLabels: false + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|redis|/spec/podTemplate/spec/resources + paths: + - schema/properties/spec/properties/verticalScaling/properties/redis/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/redis/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/redis/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue + - type: horizontal-layout + showLabels: true + label: Exporter + elements: + - type: input + label: CPU Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/cpu|/spec/verticalScaling/exporter/resources/requests/cpu + - type: input + label: CPU Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/cpu + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/cpu|/spec/verticalScaling/exporter/resources/limits/cpu + - type: input + label: Memory Requests + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/requests/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/requests/memory|/spec/verticalScaling/exporter/resources/requests/memory + - type: input + label: Memory Limits + schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/memory + init: + type: func + value: setValueFromDbDetails|/spec/monitor/prometheus/exporter/resources/limits/memory|/spec/verticalScaling/exporter/resources/limits/memory +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/redis + schema: schema/properties/spec/properties/volumeExpansion/properties/redis + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration + showLabels: false + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + elements: + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always \ No newline at end of file diff --git a/charts/opskubedbcom-redisopsrequest-editor/ui/functions.js b/charts/opskubedbcom-redisopsrequest-editor/ui/functions.js index eced4b63aa..dd4c796571 100644 --- a/charts/opskubedbcom-redisopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-redisopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,1000 +305,1012 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} + } -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + function returnFalse() { + return false + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises/${name}` - const resp = await axios.get(url) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resp.data || {} - } else return {} -} - -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.Redis?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/redisversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredRedisVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredRedisVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/redises/${name}` + const resp = await axios.get(url) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + setDiscriminatorValue('/dbDetails', resp.data || {}) + + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.Redis?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/redisversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredRedisVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredRedisVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (dbType === 'Standalone') return true - else return false - } else return false -} + return selectedType === type + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { mode } = spec || {} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } - return mode || 'Standalone' -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + const { mode } = spec || {} -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + return mode || 'Standalone' + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType() -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + if (dbType === 'Standalone') return true + else return false + } else return false + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function asDatabaseOperation() { + return !!route.params.actions + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - console.log(value) + return !ver + } - return value.includes(verd) -} + // vertical scaling + function ifDbTypeEqualsTo(value) { + const verd = getDbType() -function setReplicas({ discriminator, getValue, watchDependency }) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - const dbDetails = getValue(discriminator, '/dbDetails') - if (verd === 'Sentinel') return dbDetails?.spec?.replicas - else return dbDetails?.spec?.cluster?.replicas -} + return value.includes(verd) + } -// machine profile stuffs -let machinesFromPreset = [] + function setReplicas() { + const verd = getDbType() + const dbDetails = getValue(discriminator, '/dbDetails') + if (verd === 'Sentinel') return dbDetails?.spec?.replicas + else return dbDetails?.spec?.cluster?.replicas + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // machine profile stuffs + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} - -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.requests || {} + const annotations = dbDetails?.metadata?.annotations || {} + const machine = annotations['kubernetes.io/instance-type'] || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return { machine } + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + if (obj && Object.keys(obj).length) commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: path, + value: obj, force: true, }) + + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') + else { + annotations['kubernetes.io/instance-type'] = selectedMachine + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + } } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function isMachineCustom() { + // watchDependency('discriminator#/machine') + const machine = getValue(discriminator, '/machine') + return machine === 'custom' + } + + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} - -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + // watchDependency('discriminator#/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + setDiscriminatorValue('/applyConfig', []) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') + if (apiGroup) return apiGroup + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/remove') + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, + }) + commit('wizard/model$delete', '/spec/tls/certificates') + commit('wizard/model$delete', '/spec/tls/rotateCertificates') } } -} - -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - - return verd -} + function isIssuerRefRequired() { + const hasTls = hasTlsField() -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + return !hasTls + } - return !hasTls -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -// ************************************** Set db details ***************************************** + return !dbDetails || !dbName + } -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) - return !dbDetails || !dbName -} + if (commitPath && retValue) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - const retValue = getValue(discriminator, `/dbDetails${path}`) + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') } - return retValue || undefined -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function isVerticalScaleTopologyRequired() { + // watchDependency(`discriminator#/topologyKey`) + // watchDependency(`discriminator#/topologyValue`) -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + const key = getValue(discriminator, `/topologyKey`) + const value = getValue(discriminator, `/topologyValue`) + const path = `/spec/verticalScaling/redis/topology` -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, + }) + return '' + } else { + commit('wizard/model$delete', path) + return false + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function setApplyToIfReady() { - return 'IfReady' -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/redis/topology` + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false - } -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + const value = parseFloat(match[1]) + const unit = match[2] - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + return value * units[unit] } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} + } - return value * units[unit] -} + function disableAlias() { + return !!(model && model.alias) + } -return { - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, - setReplicas, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + setReplicas, + } } diff --git a/charts/opskubedbcom-singlestoreopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-singlestoreopsrequest-editor/ui/create-ui.yaml index 333f805354..34cf2efd87 100644 --- a/charts/opskubedbcom-singlestoreopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-singlestoreopsrequest-editor/ui/create-ui.yaml @@ -1,532 +1,567 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/topology/aggregator/replicas - label: - text: Aggregator - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/aggregator - type: input - - computed: setValueFromDbDetails|/spec/topology/leaf/replicas - label: - text: Leaf - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/leaf - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine-aggregator: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + schema: schema/properties/spec/properties/databaseRef/properties/name + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion elements: - - computed: setMachine|aggregator - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|aggregator|/spec/topology/aggregator/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-aggregator - type: select - - if: isMachineCustom|/machine-aggregator - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/aggregator/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/aggregator/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/aggregator/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/aggregator/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/aggregator/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: Aggregator - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/aggregator - show_label: true - type: single-step-form - - discriminator: - machine-leaf: - default: "" - type: string + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - computed: setMachine|leaf - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|leaf|/spec/topology/leaf/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-leaf - type: select - - if: isMachineCustom|/machine-leaf - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/leaf/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/leaf/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/leaf/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/leaf/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/leaf/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: Leaf - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/leaf - show_label: true - type: single-step-form - - discriminator: - machine-node: - default: "" - type: string + - type: input-compare + label: Aggregator + init: + type: func + value: setValueFromDbDetails|/spec/topology/aggregator/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/aggregator + - type: input-compare + label: Leaf + init: + type: func + value: setValueFromDbDetails|/spec/topology/leaf/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/leaf +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - computed: setMachine|node - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|node|/spec/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-node - type: select - - if: isMachineCustom|/machine-node - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Combined|VerticalScaling - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node - show_label: true - type: single-step-form - - computed: setResource|/spec/topology/aggregator/podTemplate/spec/containers - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: Coordinator - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources - type: resource-input-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - elements: - - computed: setValueFromDbDetails|/spec/topology/aggregator/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/aggregator - type: input - validationRuleObject: - func: checkVolume|/spec/topology/aggregator/storage/resources/requests/storage|/spec/volumeExpansion/aggregator - if: ifDbTypeEqualsTo|Topology|VolumeExpansion - label: - text: Aggregator - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/topology/leaf/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/leaf - type: input - validationRuleObject: - func: checkVolume|/spec/topology/leaf/storage/resources/requests/storage|/spec/volumeExpansion/leaf - if: ifDbTypeEqualsTo|Topology|VolumeExpansion - label: - text: Leaf - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/node - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node - if: ifDbTypeEqualsTo|Combined|VolumeExpansion - label: - text: Node - show_label: true - type: single-step-form - - label: - text: Mode - options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: block-layout + label: Aggregator Vertical Scaling + showLabels: true + if: + type: function + name: ifDbTypeEqualsTo|Topology|VerticalScaling + elements: + - type: machine-compare + label: Resources + loader: getMachines|aggregator + init: + type: func + value: setMachine|aggregator + watcher: + func: onMachineChange|aggregator|/spec/topology/aggregator/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/aggregator/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/aggregator/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/aggregator/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/aggregator/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/aggregator/properties/topology/properties/value + - type: block-layout + label: Leaf Vertical Scaling + showLabels: true + if: + type: function + name: ifDbTypeEqualsTo|Topology|VerticalScaling + elements: + - type: machine-compare + label: Resources + loader: getMachines|leaf + init: + type: func + value: setMachine|leaf + watcher: + func: onMachineChange|leaf|/spec/topology/leaf/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/leaf/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/leaf/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/leaf/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/leaf/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/leaf/properties/topology/properties/value + - type: block-layout + label: Node Vertical Scaling + showLabels: true + if: + type: function + name: ifDbTypeEqualsTo|Combined|VerticalScaling + elements: + - type: machine-compare + label: Resources + loader: getMachines|node + init: + type: func + value: setMachine|node + watcher: + func: onMachineChange|node|/spec/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value + - type: block-layout + label: Coordinator Vertical Scaling + showLabels: true + if: + type: function + name: ifDbTypeEqualsTo|Topology|VerticalScaling + elements: + - type: machine-compare + label: Resources + loader: getMachines|coordinator + init: + type: func + value: setMachine|coordinator + watcher: + func: onMachineChange|coordinator|/spec/topology/aggregator/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion + elements: + - type: block-layout + label: Aggregator Volume Expansion + showLabels: true + if: + type: function + name: ifDbTypeEqualsTo|Topology|VolumeExpansion + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/topology/aggregator/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/aggregator/storage/resources/requests/storage|/spec/volumeExpansion/aggregator + schema: schema/properties/spec/properties/volumeExpansion/properties/aggregator + - type: block-layout + label: Leaf Volume Expansion + showLabels: true + if: + type: function + name: ifDbTypeEqualsTo|Topology|VolumeExpansion + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/topology/leaf/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/leaf/storage/resources/requests/storage|/spec/volumeExpansion/leaf + schema: schema/properties/spec/properties/volumeExpansion/properties/leaf + - type: block-layout + label: Node Volume Expansion + showLabels: true + if: + type: function + name: ifDbTypeEqualsTo|Combined|VolumeExpansion + elements: + - type: input-compare + label: Storage Size + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node + schema: schema/properties/spec/properties/volumeExpansion/properties/node + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/node/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-singlestoreopsrequest-editor/ui/functions.js b/charts/opskubedbcom-singlestoreopsrequest-editor/ui/functions.js index 99b52cb778..a510abe669 100644 --- a/charts/opskubedbcom-singlestoreopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-singlestoreopsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,1013 +305,1038 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +let machinesFromPreset = [] -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resources = (resp && resp.data && resp.data.items) || [] + getDbDetails() + showAndInitOpsRequestType() + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/singlestores`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/singlestores/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.Singlestore?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/singlestoreversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/singlestores`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredSinglestoreVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredSinglestoreVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/singlestores/${name}` + const resp = await axios.get(url) + + setDiscriminatorValue('/dbDetails', resp.data || {}) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.Singlestore?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/singlestoreversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredSinglestoreVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredSinglestoreVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 + + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal + } -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, + return selectedType === type + } + + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } + + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) }) + } - if (dbType === 'Standalone') return true - else return false - } else return false -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + return spec?.tls || undefined + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType({ + discriminator, + getValue, + }) -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + if (dbType === 'Standalone') return true + else return false + } else return false + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function asDatabaseOperation() { + return !!route.params.actions + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } + + return !ver } - return !ver -} + // // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return value === verd + } -// machine profile stuffs -let machinesFromPreset = [] + // // machine profile stuffs + // let machinesFromPreset = [] + + function getMachines(type) { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = (type && type !== 'node' + ? dbDetails?.spec?.topology?.[type]?.podTemplate?.spec?.containers?.[0]?.resources?.requests + : dbDetails?.spec?.podTemplate?.spec?.containers?.[0]?.resources?.requests) || { + cpu: '', + memory: '', + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }, type) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + function setMachine(type) { + const dbDetails = getValue(discriminator, '/dbDetails') + let limits = {} + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance[type] || 'custom' + + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else { + // For coordinator, get limits from containers + if (type === 'coordinator') { + const containers = + dbDetails?.spec?.topology?.aggregator?.podTemplate?.spec?.containers || [] + const kind = dbDetails?.kind + const resource = containers.filter((ele) => ele.name === kind?.toLowerCase()) + limits = resource[0]?.resources?.requests || {} + console.log({ limits }) + } else if (type === 'node') { + const containers = dbDetails?.spec?.podTemplate?.spec?.containers || [] + const kind = dbDetails?.kind + const resource = containers.filter((ele) => ele.name === kind?.toLowerCase()) + limits = resource[0]?.resources?.requests || {} + } else { + // For aggregator and leaf + const topologyLimits = + dbDetails?.spec?.topology?.[type]?.podTemplate?.spec?.containers?.[0]?.resources + ?.requests || {} + limits = topologyLimits + } + return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } + } } - const machine = parsedInstance[type] || 'custom' - - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine-${type}`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, `/machine-${type}`) - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } - } + const path = `/spec/verticalScaling/${type}/resources` - const path = `/spec/verticalScaling/${type}/resources` + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + if (selectedMachine === 'custom') delete parsedInstance[type] + else parsedInstance[type] = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} + if (parsedInstance && Object.keys(parsedInstance).length === 0) + commit('wizard/model$delete', '/metadata/annotations') } - if (selectedMachine === 'custom') delete parsedInstance[type] - else parsedInstance[type] = selectedMachine - annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) - if (machinesFromPreset.length) - commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, - force: true, - }) + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } - if (parsedInstance && Object.keys(parsedInstance).length === 0) - commit('wizard/model$delete', '/metadata/annotations') -} + function setResource(path) { + // watchDependency('discriminator#/dbDetails') + const containers = getValue(discriminator, `/dbDetails${path}`) || [] + const kind = getValue(discriminator, '/dbDetails/kind') + const resource = containers.filter((ele) => ele.name === kind?.toLowerCase()) + return resource[0]?.resources + } -function isMachineCustom({ watchDependency, getValue, discriminator }, path) { - watchDependency(`discriminator#${path}`) - const machine = getValue(discriminator, `${path}`) - return machine === 'custom' -} + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} - -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + const watchPath = 'discriminator#/reconfigurationType' + // watchDependency(watchPath) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: `/spec/configuration/applyConfig`, + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + setDiscriminatorValue('/applyConfig', []) + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} - -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - - return verd -} -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + function isIssuerRefRequired() { + const hasTls = hasTlsField() - return !hasTls -} + return !hasTls + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -// ************************************** Set db details ***************************************** + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + return !dbDetails || !dbName + } - return !dbDetails || !dbName -} + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined - const retValue = getValue(discriminator, `/dbDetails${path}`) + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name } - return retValue || undefined -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function setResource({ discriminator, getValue, watchDependency, storeGet }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0]?.resources -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } -function setApplyToIfReady() { - return 'IfReady' -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + const value = parseFloat(match[1]) + const unit = match[2] - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/singlestore/topology` + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + return value * units[unit] } -} -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function disableAlias() { + return !!(model && model.alias) } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') - - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - - return value * units[unit] -} - -return { - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + setResource, + } } diff --git a/charts/opskubedbcom-solropsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-solropsrequest-editor/ui/create-ui.yaml index 4e49fdd807..806dc7ab8b 100644 --- a/charts/opskubedbcom-solropsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-solropsrequest-editor/ui/create-ui.yaml @@ -1,631 +1,600 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/topology/coordinator/replicas - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: coordinator - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/coordinator - type: input - - computed: setValueFromDbDetails|/spec/topology/data/replicas - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: data - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/data - type: input - - computed: setValueFromDbDetails|/spec/topology/overseer/replicas - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: overseer - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/overseer - type: input - - computed: setValueFromDbDetails|/spec/replicas - if: ifDbTypeEqualsTo|Combined|VerticalScaling - label: - text: node - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/node - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - elements: - - discriminator: - machine-coordinator: - default: "" - type: string +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType + options: + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion elements: - - computed: setMachine|coordinator - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|coordinator|/spec/topology/coordinator/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-coordinator - type: select - - if: isMachineCustom|/machine-coordinator - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: Coordinator - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/coordinator - show_label: true - type: single-step-form - - discriminator: - machine-data: - default: "" - type: string + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling elements: - - computed: setMachine|data - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|data|/spec/topology/data/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-data - type: select - - if: isMachineCustom|/machine-data - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: Data - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/data - show_label: true - type: single-step-form - - discriminator: - machine-overseer: - default: "" - type: string + - type: input-compare + label: Node + if: + type: function + name: ifDbTypeEqualsTo|Combined|HorizontalScaling + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/node + - type: block-layout + if: + type: function + name: ifDbTypeEqualsTo|Topology|HorizontalScaling + elements: + - type: input-compare + label: Coordinator + init: + type: func + value: setValueFromDbDetails|/spec/topology/coordinator/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/coordinator + - type: input-compare + label: Data + init: + type: func + value: setValueFromDbDetails|/spec/topology/data/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/data + - type: input-compare + label: Overseer + init: + type: func + value: setValueFromDbDetails|/spec/topology/overseer/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/overseer +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - computed: setMachine|overseer - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|overseer|/spec/topology/overseer/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-overseer - type: select - - if: isMachineCustom|/machine-overseer - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overseer/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overseer/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overseer/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overseer/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overseer/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Topology|VerticalScaling - label: - text: Overseer - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/overseer - show_label: true - type: single-step-form - - discriminator: - machine-node: - default: "" - type: string + - type: block-layout + label: Node Vertical Scaling + if: + type: function + name: ifDbTypeEqualsTo|Combined|VerticalScaling + elements: + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine|node + watcher: + func: onMachineChange|node|/spec/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value + - type: block-layout + label: Topology Vertical Scaling + if: + type: function + name: ifDbTypeEqualsTo|Topology|VerticalScaling + elements: + - type: block-layout + label: Coordinator Vertical Scaling + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|coordinator + init: + type: func + value: setMachine|coordinator + watcher: + func: onMachineChange|coordinator|/spec/topology/coordinator/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/coordinator/properties/topology/properties/value + - type: block-layout + label: Data Vertical Scaling + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|data + init: + type: func + value: setMachine|data + watcher: + func: onMachineChange|data|/spec/topology/data/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/data/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/data/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/data/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/data/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/data/properties/topology/properties/value + - type: block-layout + label: Overseer Vertical Scaling + showLabels: true + elements: + - type: machine-compare + label: Resources + loader: getMachines|overseer + init: + type: func + value: setMachine|overseer + watcher: + func: onMachineChange|overseer|/spec/topology/overseer/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/overseer/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/overseer/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/overseer/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true + elements: + - type: input + label: Key + schema: schema/properties/spec/properties/verticalScaling/properties/overseer/properties/topology/properties/key + - type: input + label: Value + schema: schema/properties/spec/properties/verticalScaling/properties/overseer/properties/topology/properties/value +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion elements: - - computed: setMachine|node - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|node|/spec/podTemplate/spec/containers - schema: - $ref: discriminator#/machine-node - type: select - - if: isMachineCustom|/machine-node - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/resources - type: resource-input-form - - label: - text: Node Selection Policy - options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy - type: select - - elements: - - label: - text: key - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/key - type: input - - label: - text: value - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology/properties/value - type: input - label: - text: Topology - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/topology - show_label: true - type: single-step-form - if: ifDbTypeEqualsTo|Combined|VerticalScaling - label: - text: Node - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - elements: - - computed: setValueFromDbDetails|/spec/topology/coordinator/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/coordinator - type: input - validationRuleObject: - func: checkVolume|/spec/topology/coordinator/storage/resources/requests/storage|/spec/volumeExpansion/coordinator - if: ifDbTypeEqualsTo|Topology|VolumeExpansion - label: - text: Coordinator - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/topology/data/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/data - type: input - validationRuleObject: - func: checkVolume|/spec/topology/data/storage/resources/requests/storage|/spec/volumeExpansion/data - if: ifDbTypeEqualsTo|Topology|VolumeExpansion - label: - text: Data - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/topology/overseer/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/overseer - type: input - validationRuleObject: - func: checkVolume|/spec/topology/overseer/storage/resources/requests/storage|/spec/volumeExpansion/overseer - if: ifDbTypeEqualsTo|Topology|VolumeExpansion - label: - text: Overseer - show_label: true - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.storage.size - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/node - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node - if: ifDbTypeEqualsTo|Combined|VolumeExpansion - label: - text: Node - show_label: true - type: single-step-form - - label: - text: Mode - options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: input-compare + label: Node + if: + type: function + name: ifDbTypeEqualsTo|Combined|VolumeExpansion + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node + schema: schema/properties/spec/properties/volumeExpansion/properties/node + - type: block-layout + if: + type: function + name: ifDbTypeEqualsTo|Topology|VolumeExpansion + elements: + - type: input-compare + label: Coordinator + init: + type: func + value: setValueFromDbDetails|/spec/topology/coordinator/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/coordinator/storage/resources/requests/storage|/spec/volumeExpansion/coordinator + schema: schema/properties/spec/properties/volumeExpansion/properties/coordinator + - type: input-compare + label: Data + init: + type: func + value: setValueFromDbDetails|/spec/topology/data/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/data/storage/resources/requests/storage|/spec/volumeExpansion/data + schema: schema/properties/spec/properties/volumeExpansion/properties/data + - type: input-compare + label: Overseer + init: + type: func + value: setValueFromDbDetails|/spec/topology/overseer/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/topology/overseer/storage/resources/requests/storage|/spec/volumeExpansion/overseer + schema: schema/properties/spec/properties/volumeExpansion/properties/overseer + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: block-layout + label: Configuration + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# Reconfigure TLS + - type: block-layout + label: TLS + if: + name: ifRequestTypeEqualsTo|ReconfigureTLS + type: function elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: radio + label: TLS Operation + if: + name: hasTlsField + type: function + options: + - text: Update + value: update + - text: Rotate + value: rotate + - text: Remove + value: remove + init: + type: func + value: initTlsOperation + schema: temp/properties/tlsOperation + - type: switch + label: remove + if: + name: returnFalse + type: function + schema: schema/properties/spec/properties/tls/properties/remove + - type: switch + label: rotateCertificates + schema: schema/properties/spec/properties/tls/properties/rotateCertificates + if: + name: returnFalse + type: function + - type: block-layout + label: Issuer Reference + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - discriminator: - tlsOperation: - default: update - type: string - elements: - - computed: initTlsOperation - if: hasTlsField - label: - text: labels.tlsOperation - onChange: onTlsOperationChange + - type: input + label: API Group + init: + type: func + value: initIssuerRefApiGroup + watcher: + func: initIssuerRefApiGroup + paths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + disable: true + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup + - type: select + label: Kind + options: + - text: Issuer + value: Issuer + - text: ClusterIssuer + value: ClusterIssuer + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/kind + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - type: select + label: Name + loader: + name: getIssuerRefsName + watchPaths: + - schema/properties/spec/properties/tls/properties/issuerRef/properties/kind + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/tls/issuerRef/name + validation: + type: custom + name: isIssuerRefRequired + schema: schema/properties/spec/properties/tls/properties/issuerRef/properties/name + - type: block-layout + label: Certificates + showLabels: true + if: + name: showIssuerRefAndCertificates + type: function + loader: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates + elements: + - type: select + label: Alias + loader: fetchAliasOptions + disable: disableAlias + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/alias + - type: input + label: Secret Name + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/secretName + - type: input + label: Duration + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/duration + - type: input + label: Renew Before + schema: schema/properties/spec/properties/tls/properties/certificates/items/properties/renewBefore + - type: block-layout + label: Subject + showLabels: true + elements: + - type: array-item-form + label: Organizations + schema: schema/items/properties/subject/properties/organizations + element: + type: input + label: Organization + schema: items + - type: array-item-form + label: Countries + schema: schema/items/properties/subject/properties/countries + element: + type: input + label: Country + schema: items + - type: array-item-form + label: Organizational Units + schema: schema/items/properties/subject/properties/organizationalUnits + element: + type: input + label: Organizational Unit + schema: items + - type: array-item-form + label: Provinces + schema: schema/items/properties/subject/properties/provinces + element: + type: input + label: Province + schema: items + - type: array-item-form + label: DNS Names + schema: schema/items/properties/dnsNames + element: + type: input + label: DNS Name + schema: items + - type: array-item-form + label: IP Addresses + schema: schema/items/properties/ipAddresses + element: + type: input + label: IP Address + schema: items +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady options: - - text: Update - value: update - - text: Rotate - value: rotate - - text: Remove - value: remove - schema: - $ref: discriminator#/properties/tlsOperation - type: radio - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/remove - type: switch - - if: returnFalse - schema: - $ref: schema#/properties/spec/properties/tls/properties/rotateCertificates - type: switch - - elements: - - computed: initIssuerRefApiGroup - disabled: true - label: - text: labels.api_group - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/apiGroup - type: input - - computed: setValueFromDbDetails|/spec/tls/issuerRef/kind - label: - text: labels.kind - options: - - text: Issuer - value: Issuer - - text: ClusterIssuer - value: ClusterIssuer - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/kind - sortable: true - type: select - - allowUserDefinedOption: true - computed: setValueFromDbDetails|/spec/tls/issuerRef/name - fetch: getIssuerRefsName - label: - text: labels.name - required: isIssuerRefRequired - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef/properties/name - sortable: true - type: select - if: showIssuerRefAndCertificates - schema: - $ref: schema#/properties/spec/properties/tls/properties/issuerRef - type: single-step-form - - alias: reusable_certificates - chart: - name: uibytebuildersdev-component-certificates - version: v0.27.0 - computed: setValueFromDbDetails|/spec/tls/certificates|/spec/tls/certificates - functionCallbacks: - getAliasOptions: - $ref: functions#/getAliasOptions - if: showIssuerRefAndCertificates - moduleResolver: fetchJsons - schema: - $ref: schema#/properties/spec/properties/tls/properties/certificates - type: reusable-element - if: ifRequestTypeEqualsTo|ReconfigureTLS - label: - text: labels.tls - schema: - $ref: schema#/properties/spec/properties/tls - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-solropsrequest-editor/ui/functions.js b/charts/opskubedbcom-solropsrequest-editor/ui/functions.js index 952b82d198..94637d02e4 100644 --- a/charts/opskubedbcom-solropsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-solropsrequest-editor/ui/functions.js @@ -1,3 +1,4 @@ +const { axios, useOperator, store } = window.vueHelpers || {} const machines = { 'db.t.micro': { resources: { @@ -304,1013 +305,1013 @@ const machineList = [ 'db.r.24xlarge', ] -async function fetchJsons({ axios, itemCtx }) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function returnFalse() { - return false -} +let machinesFromPreset = [] -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} +export const useFunc = (model) => { + const route = store.state?.route -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, + ) - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) + getDbDetails() + showAndInitOpsRequestType() - const resources = (resp && resp.data && resp.data.items) || [] + async function fetchJsons({ axios, itemCtx }) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/solrs`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' return { - text: name, - value: name, + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) -} + } -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + function returnFalse() { + return false + } - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/solrs/${name}` - const resp = await axios.get(url) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - return resp.data || {} - } else return {} -} - -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.Solr?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/solrversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/solrs`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredSolrVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredSolrVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/solrs/${name}` + const resp = await axios.get(url) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + setDiscriminatorValue('/dbDetails', resp.data || {}) + + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + try { + const presetVersions = presets.admin?.databases?.Solr?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/solrversions`, + { + params: queryParams, + }, + ) + const resources = (resp && resp.data && resp.data.items) || [] + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredSolrVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + return filteredSolrVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true + } -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency('model#/spec/type') - if (dbType === 'Standalone') return true - else return false - } else return false -} + return selectedType === type + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') - const { spec } = dbDetails || {} - const { topology } = spec || {} - if (topology) return 'Topology' - else return 'Combined' -} + function getDbTls() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + function getDbType() { + // watchDependency('discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') + const { spec } = dbDetails || {} + const { topology } = spec || {} + if (topology) return 'Topology' + else return 'Combined' + } -function asDatabaseOperation(route) { - return !!route.params.actions -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType() -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + if (dbType === 'Combined') return true + else return false + } else return false + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function initDatabaseRef() { + // watchDependency('model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function asDatabaseOperation() { + return !!route.params.actions + } -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + function generateOpsRequestNameForClusterUI(getValue, model, route) { + const dbName = getValue(model, '/spec/databaseRef/name') - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) + + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency('model#/spec/type') + // watchDependency('model#/spec/databaseRef/name') + const ver = asDatabaseOperation() + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + function showAndInitNamespace() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } + + return !ver } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation() + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } + + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation() } - return !ver -} + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation() + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } -// vertical scaling -function ifDbTypeEqualsTo({ discriminator, getValue, watchDependency, commit }, value, opsReqType) { - const verd = getDbType({ - discriminator, - getValue, - watchDependency, - }) - return value === verd -} + return !ver + } -// machine profile stuffs -let machinesFromPreset = [] + // vertical scaling + function ifDbTypeEqualsTo(value, opsReqType) { + const verd = getDbType() + return value === verd + } -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + // machine profile stuffs + function getMachines(type) { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = (type && type !== 'node' + ? dbDetails?.spec?.topology?.[type]?.podTemplate?.spec?.containers?.[0]?.resources?.requests + : dbDetails?.spec?.podTemplate?.spec?.containers?.[0]?.resources?.requests) || { + cpu: '', + memory: '', + } + + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } }) - .filter((val) => !!val) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr } - return arr -} -function setMachine({ getValue, discriminator, storeGet }, type) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - const machine = parsedInstance[type] || 'custom' + function setMachine(type) { + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = (type && type !== 'node' + ? dbDetails?.spec?.topology?.[type]?.podTemplate?.spec?.containers?.[0]?.resources?.requests + : dbDetails?.spec?.podTemplate?.spec?.containers?.[0]?.resources?.requests) || { + cpu: '', + memory: '', + } - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + const annotations = dbDetails?.metadata?.annotations || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + const machine = parsedInstance[type] || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, `/machine-${type}`) - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, `/machine-${type}`) + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - const instance = annotations['kubernetes.io/instance-type'] - let parsedInstance = {} - try { - if (instance) parsedInstance = JSON.parse(instance) - } catch (e) { - console.log(e) - parsedInstance = {} - } - if (selectedMachine === 'custom') delete parsedInstance[type] - else parsedInstance[type] = selectedMachine - annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + if (obj && Object.keys(obj).length) + commit('wizard/model$update', { + path: path, + value: obj, + force: true, + }) - if (machinesFromPreset.length) - commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, - force: true, - }) + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + const instance = annotations['kubernetes.io/instance-type'] + let parsedInstance = {} + try { + if (instance) parsedInstance = JSON.parse(instance) + } catch (e) { + console.log(e) + parsedInstance = {} + } + if (selectedMachine === 'custom') delete parsedInstance[type] + else parsedInstance[type] = selectedMachine + annotations['kubernetes.io/instance-type'] = JSON.stringify(parsedInstance) + + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) - if (parsedInstance && Object.keys(parsedInstance).length === 0) - commit('wizard/model$delete', '/metadata/annotations') -} + if (parsedInstance && Object.keys(parsedInstance).length === 0) + commit('wizard/model$delete', '/metadata/annotations') + } -function isMachineCustom({ watchDependency, getValue, discriminator }, path) { - watchDependency(`discriminator#${path}`) - const machine = getValue(discriminator, `${path}`) - return machine === 'custom' -} + function isMachineCustom(path) { + // watchDependency(`discriminator#${path}`) + const machine = getValue(discriminator, `${path}`) + return machine === 'custom' + } + + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency('discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList({ namespace, group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } - return ans -} -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getResourceList({ group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } + + return ans } - return ans -} -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency('model#/metadata/namespace') + + let resources = await getNamespacedResourceList({ + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList({ + group, + version, + resource, + }) -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + // watchDependency('discriminator#/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} -// for tls -function hasTlsField({ discriminator, getValue, watchDependency }) { - const tls = getDbTls({ - discriminator, - getValue, - watchDependency, - }) + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + setDiscriminatorValue('/applyConfig', []) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) - return !!tls -} + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } -function initIssuerRefApiGroup({ getValue, model, watchDependency, discriminator }) { - const kind = getValue(model, '/spec/tls/issuerRef/kind') - watchDependency('model#/spec/tls/issuerRef/kind') + // for tls + function hasTlsField() { + const tls = getDbTls() - if (kind) { - const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') - if (apiGroup) return apiGroup - return 'cert-manager.io' - } else return undefined -} + return !!tls + } -async function getIssuerRefsName({ axios, storeGet, getValue, model, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - watchDependency('model#/spec/tls/issuerRef/kind') - watchDependency('model#/metadata/namespace') - const kind = getValue(model, '/spec/tls/issuerRef/kind') - const namespace = getValue(model, '/metadata/namespace') - - if (kind === 'Issuer') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` - return getIssuer(url) - } else if (kind === 'ClusterIssuer') { - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + function initIssuerRefApiGroup() { + const kind = getValue(model, '/spec/tls/issuerRef/kind') + // watchDependency('model#/spec/tls/issuerRef/kind') - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { + if (kind) { + const apiGroup = getValue(discriminator, '/dbDetails/spec/tls/issuerRef/apiGroup') + if (apiGroup) return apiGroup + return 'cert-manager.io' + } else return undefined + } + + async function getIssuerRefsName() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + // watchDependency('model#/spec/tls/issuerRef/kind') + // watchDependency('model#/metadata/namespace') + const kind = getValue(model, '/spec/tls/issuerRef/kind') + const namespace = getValue(model, '/metadata/namespace') + + if (kind === 'Issuer') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/namespaces/${namespace}/issuers` + return getIssuer(url) + } else if (kind === 'ClusterIssuer') { + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + let clusterIssuers = presets.admin?.clusterIssuers?.available || [] + if (presets.status === '404') { + const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` + return getIssuer(url) + } + return clusterIssuers + } + + async function getIssuer(url) { try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec + const resp = await axios.get(url) + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources } catch (e) { console.log(e) - presets.status = String(e.status) + return [] } } - let clusterIssuers = presets.admin?.clusterIssuers?.available || [] - if (presets.status === '404') { - const url = `/clusters/${owner}/${cluster}/proxy/cert-manager.io/v1/clusterissuers` - return getIssuer(url) - } - return clusterIssuers } - async function getIssuer(url) { - try { - const resp = await axios.get(url) - const resources = (resp && resp.data && resp.data.items) || [] + function initTlsOperation() { + return 'update' + } - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true + function onTlsOperationChange() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + + commit('wizard/model$delete', '/spec/tls') + + if (tlsOperation === 'rotate') { + commit('wizard/model$update', { + path: '/spec/tls/rotateCertificates', + value: true, + force: true, + }) + } else if (tlsOperation === 'remove') { + commit('wizard/model$update', { + path: '/spec/tls/remove', + value: true, + force: true, }) - return resources - } catch (e) { - console.log(e) - return [] } } -} -function initTlsOperation() { - return 'update' -} -function onTlsOperationChange({ discriminator, getValue, commit }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - - commit('wizard/model$delete', '/spec/tls') + function showIssuerRefAndCertificates() { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // watchDependency('discriminator#/tlsOperation') + const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' - if (tlsOperation === 'rotate') { - commit('wizard/model$update', { - path: '/spec/tls/rotateCertificates', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/remove') - } else if (tlsOperation === 'remove') { - commit('wizard/model$update', { - path: '/spec/tls/remove', - value: true, - force: true, - }) - commit('wizard/model$delete', '/spec/tls/certificates') - commit('wizard/model$delete', '/spec/tls/rotateCertificates') + return verd } -} -function showIssuerRefAndCertificates({ discriminator, getValue, watchDependency }) { - const tlsOperation = getValue(discriminator, '/tlsOperation') - watchDependency('discriminator#/tlsOperation') - const verd = tlsOperation !== 'remove' && tlsOperation !== 'rotate' + function isIssuerRefRequired() { + const hasTls = hasTlsField() - return verd -} - -function isIssuerRefRequired({ discriminator, getValue, watchDependency }) { - const hasTls = hasTlsField({ - discriminator, - getValue, - watchDependency, - }) + return !hasTls + } - return !hasTls -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading() + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} + function isDbDetailsLoading() { + // watchDependency('discriminator#/dbDetails') + // watchDependency('model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') -// ************************************** Set db details ***************************************** + return !dbDetails || !dbName + } -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + function setValueFromDbDetails(path, commitPath) { + const retValue = getValue(discriminator, `/dbDetails${path}`) - return !dbDetails || !dbName -} + if (commitPath) { + const tlsOperation = getValue(discriminator, '/tlsOperation') + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') - - const retValue = getValue(discriminator, `/dbDetails${path}`) + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } + return retValue || undefined + } - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + function getAliasOptions() { + return ['server', 'client', 'metrics-exporter'] + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name } - return retValue || undefined -} + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } -function setResource({ discriminator, getValue, watchDependency, storeGet }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0].resources -} + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails() + } -function getAliasOptions() { - return ['server', 'client', 'metrics-exporter'] -} + function setApplyToIfReady() { + return 'IfReady' + } -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } -function setApplyToIfReady() { - return 'IfReady' -} + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + const value = parseFloat(match[1]) + const unit = match[2] - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/solr/topology` + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + return value * units[unit] } -} -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function fetchAliasOptions() { + return getAliasOptions ? getAliasOptions() : [] + } - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + function validateNewCertificates({ itemCtx }) { + const addedAliases = (model && model.map((item) => item.alias)) || [] - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + if (addedAliases.includes(itemCtx.alias) && itemCtx.isCreate) { + return { isInvalid: true, message: 'Alias already exists' } + } + return {} } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, + function disableAlias() { + return !!(model && model.alias) } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') - - const value = parseFloat(match[1]) - const unit = match[2] - - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - - return value * units[unit] -} - -return { - setResource, - fetchJsons, - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - ifDbTypeEqualsTo, - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - hasTlsField, - initIssuerRefApiGroup, - getIssuerRefsName, - initTlsOperation, - onTlsOperationChange, - showIssuerRefAndCertificates, - isIssuerRefRequired, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - getAliasOptions, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + fetchAliasOptions, + validateNewCertificates, + disableAlias, + isRancherManaged, + fetchJsons, + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + disableOpsRequest, + initNamespace, + initDatabaseRef, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + ifDbTypeEqualsTo, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + hasTlsField, + initIssuerRefApiGroup, + getIssuerRefsName, + initTlsOperation, + onTlsOperationChange, + showIssuerRefAndCertificates, + isIssuerRefRequired, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + getAliasOptions, + isNamespaceDisabled, + isDatabaseRefDisabled, + onDbChange, + onNamespaceChange, + setApplyToIfReady, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/opskubedbcom-zookeeperopsrequest-editor/ui/create-ui.yaml b/charts/opskubedbcom-zookeeperopsrequest-editor/ui/create-ui.yaml index 7d7020daa3..91ab3aaafb 100644 --- a/charts/opskubedbcom-zookeeperopsrequest-editor/ui/create-ui.yaml +++ b/charts/opskubedbcom-zookeeperopsrequest-editor/ui/create-ui.yaml @@ -1,313 +1,282 @@ -steps: -- form: - discriminator: - dbDetails: - type: object +type: multi-step-form +step: + - type: single-step-form + loader: getDbDetails elements: - - computed: getDbDetails - if: returnFalse - schema: - $ref: discriminator#/properties/dbDetails - type: input - - if: showAndInitName - label: - text: labels.op_req_name - required: true - schema: - $ref: schema#/properties/metadata/properties/name - type: input - - computed: initNamespace - disabled: isNamespaceDisabled - fetch: getNamespaces - hasGroup: isRancherManaged - if: showAndInitNamespace - label: - text: labels.namespace - onChange: onNamespaceChange - required: true - schema: - $ref: schema#/properties/metadata/properties/namespace - type: select - - computed: initDatabaseRef - disabled: isDatabaseRefDisabled - fetch: getDbs - if: showAndInitDatabaseRef - label: - text: labels.databaseRef - onChange: onDbChange - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/databaseRef/properties/name - type: select - - if: showConfigureOpsrequestLabel - label: - text: labels.config_ops_request - type: label-element - - computed: getRequestTypeFromRoute - disabled: isDbDetailsLoading - hasDescription: true - if: showAndInitOpsRequestType - individualItemDisabilityCheck: disableOpsRequest - label: - text: labels.ops_request_type - onChange: onRequestTypeChange - options: - - description: options.UpdateVersion.description - text: options.UpdateVersion.text - value: UpdateVersion - - description: options.HorizontalScaling.description - text: options.HorizontalScaling.text - value: HorizontalScaling - - description: options.VerticalScaling.description - text: options.VerticalScaling.text - value: VerticalScaling - - description: options.VolumeExpansion.description - text: options.VolumeExpansion.text - value: VolumeExpansion - - description: options.Restart.description - text: options.Restart.text - value: Restart - - description: options.Reconfigure.description - text: options.Reconfigure.text - value: Reconfigure - - description: options.ReconfigureTLS.description - text: options.ReconfigureTLS.text - value: ReconfigureTLS - schema: - $ref: schema#/properties/spec/properties/type - type: radio - - elements: - - computed: setValueFromDbDetails|/spec/version - fetch: getDbVersions - label: - text: labels.targetVersion - schema: - $ref: schema#/properties/spec/properties/updateVersion/properties/targetVersion - type: select - if: ifRequestTypeEqualsTo|UpdateVersion - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/replicas - label: - text: labels.replicas - schema: - $ref: schema#/properties/spec/properties/horizontalScaling/properties/replicas - type: input - if: ifRequestTypeEqualsTo|HorizontalScaling - label: - text: Horizontal Scaling Form - type: single-step-form - - discriminator: - machine: - default: "" - type: string - elements: - - computed: setMachine - customClass: mt-20 - disableUnselect: true - fetch: getMachines - label: - text: Machine Profile - onChange: onMachineChange|node|/spec/podTemplate/spec/containers - schema: - $ref: discriminator#/machine - type: select - - if: isMachineCustom - label: - text: labels.resources - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/resources - type: resource-input-form - - label: - text: labels.node_selection_policy +# common + - type: input + label: op_req_name + if: + type: function + name: showAndInitName + validation: + type: required + schema: schema/properties/metadata/properties/name + - type: select + label: Namespace + if: + type: function + name: showAndInitNamespace + init: + type: func + value: initNamespace + disable: isNamespaceDisabled + loader: getNamespaces + validation: + type: required + hasGroup: isRancherManaged + schema: schema/properties/metadata/properties/namespace + - type: select + label: Database Ref + if: + type: function + name: showAndInitDatabaseRef + loader: + name: getDbs + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: initDatabaseRef + validation: + type: required + disable: isDatabaseRefDisabled + refresh: true + watcher: + func: onDbChange + paths: + - schema/properties/spec/properties/databaseRef/properties/name + schema: schema/properties/spec/properties/databaseRef/properties/name + - type: label-element + label: config_ops_request + if: + type: function + name: showConfigureOpsrequestLabel + - type: radio + label: Type of Ops Request + if: + type: function + name: showAndInitOpsRequestType options: - - text: LabelSelector - value: LabelSelector - - text: Taint - value: Taint - schema: - $ref: schema#/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy - type: select - - discriminator: - topologyKey: - default: "" - type: string - topologyValue: - default: "" - type: string + - description: Update your database to any version + text: Update Version + value: UpdateVersion + - description: Scale up or down pod count + text: Horizontal Scaling + value: HorizontalScaling + - description: Manage your CPU resources + text: Vertical Scaling + value: VerticalScaling + - description: Manage your database size + text: Volume Expansion + value: VolumeExpansion + - description: Restart your database + text: Restart + value: Restart + - description: Reconfigure your database + text: Reconfigure + value: Reconfigure + - description: Reconfigure your database tls configuration + text: Reconfigure TLS + value: ReconfigureTLS + init: + type: func + value: getRequestTypeFromRoute + disable: isDbDetailsLoading + watcher: + func: isDbDetailsLoading + paths: + - temp/dbDetails + - schema/properties/spec/properties/databaseRef/properties/name + isHorizontal: true + schema: schema/properties/spec/properties/type +# UpdateVersion + - type: block-layout + showLabels: false + if: + type: function + name: ifRequestTypeEqualsTo|UpdateVersion elements: - - label: - text: labels.key - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyKey - type: input - - label: - text: labels.value - required: isVerticalScaleTopologyRequired - schema: - $ref: discriminator#/topologyValue - type: input - label: - text: labels.topology - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|VerticalScaling - type: single-step-form - - elements: - - computed: setValueFromDbDetails|/spec/storage/resources/requests/storage - label: - text: labels.node - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/node - type: input - validationRuleObject: - func: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node - - label: - text: Mode - options: - - text: Offline - value: Offline - - text: Online - value: Online - required: true - schema: - $ref: schema#/properties/spec/properties/volumeExpansion/properties/mode - type: select - if: ifRequestTypeEqualsTo|VolumeExpansion - label: - text: Volume Expansion Form - type: single-step-form - - elements: - - discriminator: - reconfigurationType: - type: string + - type: select + label: Target Version + init: + type: func + value: setValueFromDbDetails|/spec/version + loader: getDbVersions + schema: schema/properties/spec/properties/updateVersion/properties/targetVersion +# Horizontal Scale + - type: block-layout + label: Horizontal Scaling Form + if: + type: function + name: ifRequestTypeEqualsTo|HorizontalScaling + elements: + - type: input-compare + label: Replicas + init: + type: func + value: setValueFromDbDetails|/spec/replicas + schema: schema/properties/spec/properties/horizontalScaling/properties/replicas +# vertical Scale + - type: block-layout + if: + type: function + name: ifRequestTypeEqualsTo|VerticalScaling elements: - - label: - text: labels.reconfigurationType - onChange: onReconfigurationTypeChange - options: - - text: Select New Config Secret - value: selectNewConfigSecret - - text: Apply Config - value: applyConfig - - text: Remove - value: remove - required: true - schema: - $ref: discriminator#/properties/reconfigurationType - type: radio - - elements: - - add_new_button: - label: labels.createConfig - target: _blank - url: - function: createSecretUrl - computed: setValueFromDbDetails|/spec/configSecret/name - fetch: getConfigSecrets - label: - text: labels.configSecret - refresh: true - required: true - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret/properties/name - type: select - if: ifReconfigurationTypeEqualsTo|selectNewConfigSecret - label: - text: Configuration config secret - schema: - $ref: schema#/properties/spec/properties/configuration/properties/configSecret - type: single-step-form - - addFormLabel: labels.applyConfig.label - element: - discriminator: - configArray: - emitAs: applyConfig - type: array + - type: machine-compare + label: Resources + loader: getMachines + init: + type: func + value: setMachine + watcher: + func: onMachineChange|node|/spec/podTemplate/spec/containers + paths: + - schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/resources + - type: select + label: Node Selection Policy + options: + - text: LabelSelector + value: LabelSelector + - text: Taint + value: Taint + schema: schema/properties/spec/properties/verticalScaling/properties/node/properties/nodeSelectionPolicy + - type: block-layout + label: Topology + showLabels: true elements: - - label: - text: labels.applyConfig.key - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/key - type: input - - label: - text: labels.applyConfig.value - required: true - schema: - $ref: discriminator#/properties/configArray/items/properties/value - type: editor - type: single-step-form - if: ifReconfigurationTypeEqualsTo|applyConfig - label: - text: labels.applyConfig.label - onChange: onApplyconfigChange - required: true - schema: - $ref: discriminator#/properties/applyConfig - tableContents: - - inTableColumn: true - label: - text: labels.applyConfig.key - path: key - type: value - typeOfValue: string - - inTableColumn: true - label: - text: labels.applyConfig.value - path: value - type: value - typeOfValue: code - type: single-step-form-array - - if: returnFalse - label: - text: labels.removeCustomConfig - schema: - $ref: schema#/properties/spec/properties/configuration/properties/removeCustomConfig - type: switch - label: - text: labels.configuration - schema: - $ref: schema#/properties/spec/properties/configuration - show_label: true - type: single-step-form - if: ifRequestTypeEqualsTo|Reconfigure - label: - text: Reconfigure Form - type: single-step-form - - label: - text: labels.timeout - options: - - text: 5 minutes - value: 5m - - text: 10 minutes - value: 10m - - text: 30 minutes - value: 30m - - text: 1 hour - value: 1h - - text: 2 hours - value: 2h - - text: 5 hours - value: 5h - - text: 10 hours - value: 10h - schema: - $ref: schema#/properties/spec/properties/timeout - type: select - - computed: setApplyToIfReady - label: - text: labels.apply - options: - - text: IfReady (OpsRequest will be applied if database is ready) - value: IfReady - - text: Always (OpsRequest will always be applied) - value: Always - schema: - $ref: schema#/properties/spec/properties/apply - type: radio - type: single-step-form - id: basic - title: steps.0.label -type: multi-step-form + - type: input + label: Key + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyKey + - type: input + label: Value + validation: + type: custom + name: isVerticalScaleTopologyRequired + schema: temp/topologyValue +# Volume Expansion + - type: block-layout + label: Volume Expansion Form + if: + type: function + name: ifRequestTypeEqualsTo|VolumeExpansion + elements: + - type: input-compare + label: Node + init: + type: func + value: setValueFromDbDetails|/spec/storage/resources/requests/storage + validation: + type: custom + name: checkVolume|/spec/storage/resources/requests/storage|/spec/volumeExpansion/node + schema: schema/properties/spec/properties/volumeExpansion/properties/node + - type: select + label: Mode + options: + - text: Offline + value: Offline + - text: Online + value: Online + validation: + type: required + schema: schema/properties/spec/properties/volumeExpansion/properties/mode +# Reconfigure + - type: block-layout + label: Reconfigure Form + if: + name: ifRequestTypeEqualsTo|Reconfigure + type: function + elements: + - type: radio + label: Reconfigure Type + options: + - text: Select New Config Secret + value: selectNewConfigSecret + - text: Apply Config + value: applyConfig + - text: Remove + value: remove + watcher: + func: onReconfigurationTypeChange + paths: + - temp/properties/reconfigurationType + validation: + type: required + schema: temp/properties/reconfigurationType + - type: block-layout + label: Configuration config secret + showLabels: false + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + elements: + - type: select + addNewButton: + label: Create Secret + target: _blank + url: + function: createSecretUrl + label: Config Secret + if: + name: ifReconfigurationTypeEqualsTo|selectNewConfigSecret + type: function + loader: + name: getConfigSecrets + watchPaths: + - schema/properties/metadata/properties/namespace + init: + type: func + value: setValueFromDbDetails|/spec/configSecret/name + refresh: true + validation: + type: required + schema: schema/properties/spec/properties/configuration/properties/configSecret/properties/name + - type: array-object-form + label: Apply Config + if: + name: ifReconfigurationTypeEqualsTo|applyConfig + type: function + validation: + type: required + watcher: + func: onApplyconfigChange + paths: + - temp/properties/applyConfig + schema: temp/properties/applyConfig + elements: + - type: input + label: key + validation: + type: required + schema: temp/properties/configArray/items/properties/key + - type: editor + hasCopy: false + label: value + validation: + type: required + schema: temp/properties/configArray/items/properties/value + - type: switch + schema: schema/properties/spec/properties/configuration/properties/removeCustomConfig + label: Remove CustomConfig + if: + name: returnFalse + type: function +# common + - type: time-picker + label: Timeout + schema: 'schema/properties/spec/properties/timeout' + - type: radio + label: apply + schema: 'schema/properties/spec/properties/apply' + init: + type: func + value: setApplyToIfReady + options: + - text: IfReady (OpsRequest will be applied if database is ready) + value: IfReady + - text: Always (OpsRequest will always be applied) + value: Always diff --git a/charts/opskubedbcom-zookeeperopsrequest-editor/ui/functions.js b/charts/opskubedbcom-zookeeperopsrequest-editor/ui/functions.js index ececbe335a..40f7b1561b 100644 --- a/charts/opskubedbcom-zookeeperopsrequest-editor/ui/functions.js +++ b/charts/opskubedbcom-zookeeperopsrequest-editor/ui/functions.js @@ -1,3 +1,5 @@ +const { axios, useOperator, store } = window.vueHelpers || {} + const machines = { 'db.t.micro': { resources: { @@ -304,827 +306,857 @@ const machineList = [ 'db.r.24xlarge', ] -function returnFalse() { - return false -} - -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} - -async function getNamespaces({ axios, storeGet }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - - const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { - params: { filter: { items: { metadata: { name: null } } } }, - }) - - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbs({ axios, storeGet, model, getValue, watchDependency }) { - if (storeGet('/route/params/actions')) return [] - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') +let machinesFromPreset = [] - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') +export const useFunc = (model) => { + const route = store.state?.route - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/zookeepers`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, + const { getValue, storeGet, discriminator, setDiscriminatorValue, commit } = useOperator( + model, + store.state, ) - const resources = (resp && resp.data && resp.data.items) || [] - - return resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} - -async function getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') - const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + getDbDetails() + showAndInitOpsRequestType() - if (namespace && name) { - const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/zookeepers/${name}` - const resp = await axios.get(url) + function returnFalse() { + return false + } - setDiscriminatorValue('/dbDetails', resp.data || {}) + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } - return resp.data || {} - } else return {} -} + async function getNamespaces() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getDbVersions({ axios, storeGet, getValue, discriminator }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const resp = await axios.get(`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces`, { + params: { filter: { items: { metadata: { name: null } } } }, + }) - const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + const resources = (resp && resp.data && resp.data.items) || [] - let presets = storeGet('/kubedbuiPresets') || {} - if (!storeGet('/route/params/actions')) { - try { - const presetResp = await axios.get(url) - presets = presetResp.data?.spec?.values?.spec - } catch (e) { - console.log(e) - presets.status = String(e.status) - } + return resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + return { + text: name, + value: name, + } + }) } - try { - const presetVersions = presets.admin?.databases?.ZooKeeper?.versions?.available || [] - const queryParams = { - filter: { - items: { - metadata: { name: null }, - spec: { version: null, deprecated: null, updateConstraints: null }, - }, - }, - } + async function getDbs() { + if (storeGet('/route/params/actions')) return [] + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const namespace = getValue(model, '/metadata/namespace') + // watchDependency'model#/metadata/namespace') const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/zookeeperversions`, + `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/zookeepers`, { - params: queryParams, + params: { filter: { items: { metadata: { name: null } } } }, }, ) const resources = (resp && resp.data && resp.data.items) || [] - const sortedVersions = resources.sort((a, b) => versionCompare(a.spec.version, b.spec.version)) - - let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' - const found = sortedVersions.find((item) => item.metadata.name === ver) - - if (found) ver = found.spec?.version - const allowed = found?.spec?.updateConstraints?.allowlist || [] - const limit = allowed.length ? allowed[0] : '0.0' - - // keep only non deprecated & kubedb-ui-presets & within constraints of current version - // if presets.status is 404, it means no presets available, no need to filter with presets - const filteredZooKeeperVersions = sortedVersions.filter((item) => { - // default limit 0.0 means no restrictions, show all higher versions - if (limit === '0.0') - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - versionCompare(item.spec?.version, ver) >= 0 - ) - // if limit doesn't have any operator, it's a single version - else if (!limit.match(/^(>=|<=|>|<)/)) - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - item.spec?.version === limit - ) - // if limit has operator, check version with constraints - else - return ( - !item.spec?.deprecated && - (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && - isVersionWithinConstraints(item.spec?.version, limit) - ) - }) - - return filteredZooKeeperVersions.map((item) => { + return resources.map((item) => { const name = (item.metadata && item.metadata.name) || '' - const specVersion = (item.spec && item.spec.version) || '' return { - text: `${name} (${specVersion})`, + text: name, value: name, } }) - } catch (e) { - console.log(e) - return [] } -} -function versionCompare(v1, v2) { - const arr1 = v1.split('.').map(Number) - const arr2 = v2.split('.').map(Number) + async function getDbDetails() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace') + const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name') + + if (namespace && name) { + const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/zookeepers/${name}` + const resp = await axios.get(url) - for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { - const num1 = arr1[i] || 0 - const num2 = arr2[i] || 0 + setDiscriminatorValue('/dbDetails', resp.data || {}) - if (num1 > num2) return 1 // v1 is higher - if (num1 < num2) return -1 // v2 is higher + return resp.data || {} + } else return {} } - return 0 // versions are equal -} -function isVersionWithinConstraints(version, constraints) { - let constraintsArr = [] - if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) - else constraintsArr = [constraints] - - for (let constraint of constraintsArr) { - let match = constraint.match(/^(>=|<=|>|<)/) - let operator = match ? match[0] : '' - let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() - - let comparison = versionCompare(version, constraintVersion) - if ( - (operator === '>=' && comparison < 0) || - (operator === '<=' && comparison > 0) || - (operator === '>' && comparison <= 0) || - (operator === '<' && comparison >= 0) - ) - return false + async function getDbVersions() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const url = `/clusters/${owner}/${cluster}/proxy/charts.x-helm.dev/v1alpha1/clusterchartpresets/kubedb-ui-presets` + + let presets = storeGet('/kubedbuiPresets') || {} + if (!storeGet('/route/params/actions')) { + try { + const presetResp = await axios.get(url) + presets = presetResp.data?.spec?.values?.spec + } catch (e) { + console.log(e) + presets.status = String(e.status) + } + } + + try { + const presetVersions = presets.admin?.databases?.ZooKeeper?.versions?.available || [] + const queryParams = { + filter: { + items: { + metadata: { name: null }, + spec: { version: null, deprecated: null, updateConstraints: null }, + }, + }, + } + + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/catalog.kubedb.com/v1alpha1/zookeeperversions`, + { + params: queryParams, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + const sortedVersions = resources.sort((a, b) => + versionCompare(a.spec.version, b.spec.version), + ) + + let ver = getValue(discriminator, '/dbDetails/spec/version') || '0' + const found = sortedVersions.find((item) => item.metadata.name === ver) + + if (found) ver = found.spec?.version + const allowed = found?.spec?.updateConstraints?.allowlist || [] + const limit = allowed.length ? allowed[0] : '0.0' + + // keep only non deprecated & kubedb-ui-presets & within constraints of current version + // if presets.status is 404, it means no presets available, no need to filter with presets + const filteredZooKeeperVersions = sortedVersions.filter((item) => { + // default limit 0.0 means no restrictions, show all higher versions + if (limit === '0.0') + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + versionCompare(item.spec?.version, ver) >= 0 + ) + // if limit doesn't have any operator, it's a single version + else if (!limit.match(/^(>=|<=|>|<)/)) + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + item.spec?.version === limit + ) + // if limit has operator, check version with constraints + else + return ( + !item.spec?.deprecated && + (presets.status === '404' || presetVersions.includes(item.metadata?.name)) && + isVersionWithinConstraints(item.spec?.version, limit) + ) + }) + + return filteredZooKeeperVersions.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + const specVersion = (item.spec && item.spec.version) || '' + return { + text: `${name} (${specVersion})`, + value: name, + } + }) + } catch (e) { + console.log(e) + return [] + } } - return true -} -function ifRequestTypeEqualsTo({ model, getValue, watchDependency }, type) { - const selectedType = getValue(model, '/spec/type') - watchDependency('model#/spec/type') + function versionCompare(v1, v2) { + const arr1 = v1.split('.').map(Number) + const arr2 = v2.split('.').map(Number) - return selectedType === type -} + for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { + const num1 = arr1[i] || 0 + const num2 = arr2[i] || 0 + + if (num1 > num2) return 1 // v1 is higher + if (num1 < num2) return -1 // v2 is higher + } + return 0 // versions are equal + } -function onRequestTypeChange({ model, getValue, commit }) { - const selectedType = getValue(model, '/spec/type') - const reqTypeMapping = { - Upgrade: 'updateVersion', - UpdateVersion: 'updateVersion', - HorizontalScaling: 'horizontalScaling', - VerticalScaling: 'verticalScaling', - VolumeExpansion: 'volumeExpansion', - Restart: 'restart', - Reconfigure: 'configuration', - ReconfigureTLS: 'tls', + function isVersionWithinConstraints(version, constraints) { + let constraintsArr = [] + if (constraints.includes(',')) constraintsArr = constraints?.split(',')?.map((c) => c.trim()) + else constraintsArr = [constraints] + + for (let constraint of constraintsArr) { + let match = constraint.match(/^(>=|<=|>|<)/) + let operator = match ? match[0] : '' + let constraintVersion = constraint.replace(/^(>=|<=|>|<)/, '').trim() + + let comparison = versionCompare(version, constraintVersion) + if ( + (operator === '>=' && comparison < 0) || + (operator === '<=' && comparison > 0) || + (operator === '>' && comparison <= 0) || + (operator === '<' && comparison >= 0) + ) + return false + } + return true } - Object.keys(reqTypeMapping).forEach((key) => { - if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) - }) -} + function ifRequestTypeEqualsTo(type) { + const selectedType = getValue(model, '/spec/type') + // watchDependency'model#/spec/type') -function disableOpsRequest({ itemCtx, discriminator, getValue, watchDependency }) { - if (itemCtx.value === 'HorizontalScaling') { - const dbType = getDbType({ - discriminator, - getValue, - watchDependency, - }) + return selectedType === type + } - if (dbType === 'Standalone') return true - else return false - } else return false -} + function onRequestTypeChange() { + const selectedType = getValue(model, '/spec/type') + const reqTypeMapping = { + Upgrade: 'updateVersion', + UpdateVersion: 'updateVersion', + HorizontalScaling: 'horizontalScaling', + VerticalScaling: 'verticalScaling', + VolumeExpansion: 'volumeExpansion', + Restart: 'restart', + Reconfigure: 'configuration', + ReconfigureTLS: 'tls', + } -function getDbTls({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + Object.keys(reqTypeMapping).forEach((key) => { + if (key !== selectedType) commit('wizard/model$delete', `/spec/${reqTypeMapping[key]}`) + }) + } - const { spec } = dbDetails || {} - return spec?.tls || undefined -} + function disableOpsRequest() { + if (itemCtx.value === 'HorizontalScaling') { + const dbType = getDbType({ + discriminator, + getValue, + }) -function getDbType({ discriminator, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - const dbDetails = getValue(discriminator, '/dbDetails') + if (dbType === 'Standalone') return true + else return false + } else return false + } - const { spec } = dbDetails || {} - const { mode } = spec || {} + function getDbTls() { + // watchDependency'discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') - return mode || 'Standalone' -} + const { spec } = dbDetails || {} + return spec?.tls || undefined + } -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} + function getDbType() { + // watchDependency'discriminator#/dbDetails') + const dbDetails = getValue(discriminator, '/dbDetails') -function initDatabaseRef({ route, watchDependency }) { - watchDependency('model#/metadata/namespace') - const { name } = route.params || {} - return name -} + const { spec } = dbDetails || {} + const { mode } = spec || {} -function asDatabaseOperation(route) { - return !!route.params.actions -} + return mode || 'Standalone' + } -function generateOpsRequestNameForClusterUI(getValue, model, route) { - const dbName = getValue(model, '/spec/databaseRef/name') + function initNamespace() { + const { namespace } = route.query || {} + return namespace || null + } - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + function initDatabaseRef() { + // watchDependency'model#/metadata/namespace') + const { name } = route.params || {} + return name + } - const resources = route.params.resource || '' - const resource = resources.slice(0, -1) + function asDatabaseOperation(route) { + return !!route.params.actions + } - const opsName = dbName ? dbName : resource - return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` -} + function generateOpsRequestNameForClusterUI() { + const dbName = getValue(model, '/spec/databaseRef/name') -function showAndInitName({ route, commit, getValue, model, watchDependency }) { - watchDependency('model#/spec/type') - watchDependency('model#/spec/databaseRef/name') - const ver = asDatabaseOperation(route) + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' - const selectedType = getValue(model, '/spec/type') - const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + const resources = route.params.resource || '' + const resource = resources.slice(0, -1) - if (ver) { - // For kubedb-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, - force: true, - }) - } else { - // For cluster-ui - commit('wizard/model$update', { - path: '/metadata/name', - value: generateOpsRequestNameForClusterUI(getValue, model, route), - force: true, - }) + const opsName = dbName ? dbName : resource + return `${opsName}-${Math.floor(Date.now() / 1000)}${lowerType ? '-' + lowerType : ''}` } - return !ver -} -function showAndInitNamespace({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/metadata/namespace', - value: `${route.query.namespace}`, - force: true, - }) + + function showAndInitName() { + // watchDependency'model#/spec/type') + // watchDependency'model#/spec/databaseRef/name') + const ver = asDatabaseOperation(route) + + const selectedType = getValue(model, '/spec/type') + const lowerType = selectedType ? String(selectedType).toLowerCase() : '' + + if (ver) { + // For kubedb-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: `${route.params.name}-${Math.floor(Date.now() / 1000)}-${lowerType}`, + force: true, + }) + } else { + // For cluster-ui + commit('wizard/model$update', { + path: '/metadata/name', + value: generateOpsRequestNameForClusterUI(getValue, model, route), + force: true, + }) + } + return !ver } + function showAndInitNamespace() { + const ver = asDatabaseOperation(route) + if (ver) { + commit('wizard/model$update', { + path: '/metadata/namespace', + value: `${route.query.namespace}`, + force: true, + }) + } - return !ver -} -function showAndInitDatabaseRef({ route, commit }) { - const ver = asDatabaseOperation(route) - if (ver) { - commit('wizard/model$update', { - path: '/spec/databaseRef/name', - value: `${route.params.name}`, - force: true, - }) + return !ver } + function showAndInitDatabaseRef() { + const ver = asDatabaseOperation(route) + if (ver) { + commit('wizard/model$update', { + path: '/spec/databaseRef/name', + value: `${route.params.name}`, + force: true, + }) + } - return !ver -} -function showConfigureOpsrequestLabel({ route }) { - return !asDatabaseOperation(route) -} -function showAndInitOpsRequestType({ route, commit }) { - const ver = asDatabaseOperation(route) - const opMap = { - upgrade: 'UpdateVersion', - updateVersion: 'UpdateVersion', - horizontalscaling: 'HorizontalScaling', - verticalscaling: 'VerticalScaling', - volumeexpansion: 'VolumeExpansion', - restart: 'Restart', - reconfiguretls: 'ReconfigureTLS', - reconfigure: 'Reconfigure', + return !ver } - if (ver) { - const operation = route.params.actions - const match = /^(.*)-opsrequest-(.*)$/.exec(operation) - const opstype = match[2] - commit('wizard/model$update', { - path: '/spec/type', - value: opMap[opstype], - force: true, - }) + function showConfigureOpsrequestLabel() { + return !asDatabaseOperation(route) + } + function showAndInitOpsRequestType() { + const ver = asDatabaseOperation(route) + const opMap = { + upgrade: 'UpdateVersion', + updateVersion: 'UpdateVersion', + horizontalscaling: 'HorizontalScaling', + verticalscaling: 'VerticalScaling', + volumeexpansion: 'VolumeExpansion', + restart: 'Restart', + reconfiguretls: 'ReconfigureTLS', + reconfigure: 'Reconfigure', + } + if (ver) { + const operation = route.params.actions + const match = /^(.*)-opsrequest-(.*)$/.exec(operation) + const opstype = match[2] + commit('wizard/model$update', { + path: '/spec/type', + value: opMap[opstype], + force: true, + }) + } + + return !ver } - return !ver -} + // for config secret + async function getConfigSecrets() { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + const namespace = getValue(model, '/metadata/namespace') + // watchDependency'model#/metadata/namespace') -// for config secret -async function getConfigSecrets({ storeGet, axios, model, getValue, watchDependency }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, - { - params: { - filter: { items: { metadata: { name: null }, type: null } }, + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`, + { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, }, - }, - ) + ) - const secrets = (resp && resp.data && resp.data.items) || [] + const secrets = (resp && resp.data && resp.data.items) || [] - const filteredSecrets = secrets + const filteredSecrets = secrets - filteredSecrets.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return filteredSecrets -} + filteredSecrets.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return filteredSecrets + } -function createSecretUrl({ storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function createSecretUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/secrets/create` + } } -} -function isEqualToValueFromType({ discriminator, getValue, watchDependency }, value) { - watchDependency('discriminator#/valueFromType') - const valueFrom = getValue(discriminator, '/valueFromType') - return valueFrom === value -} + function isEqualToValueFromType(value) { + // watchDependency'discriminator#/valueFromType') + const valueFrom = getValue(discriminator, '/valueFromType') + return valueFrom === value + } -async function getNamespacedResourceList(axios, storeGet, { namespace, group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + async function getNamespacedResourceList( + axios, + storeGet, + { namespace, group, version, resource }, + ) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/namespaces/${namespace}/${resource}` - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) + + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - return ans -} + async function getResourceList(axios, storeGet, { group, version, resource }) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') -async function getResourceList(axios, storeGet, { group, version, resource }) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` - const url = `/clusters/${owner}/${cluster}/proxy/${group}/${version}/${resource}` + let ans = [] + try { + const resp = await axios.get(url, { + params: { + filter: { items: { metadata: { name: null }, type: null } }, + }, + }) - let ans = [] - try { - const resp = await axios.get(url, { - params: { - filter: { items: { metadata: { name: null }, type: null } }, - }, - }) + const items = (resp && resp.data && resp.data.items) || [] + ans = items + } catch (e) { + console.log(e) + } - const items = (resp && resp.data && resp.data.items) || [] - ans = items - } catch (e) { - console.log(e) + return ans } - return ans -} + async function resourceNames(group, version, resource) { + const namespace = getValue(model, '/metadata/namespace') + // watchDependency'model#/metadata/namespace') -async function resourceNames( - { axios, getValue, model, watchDependency, storeGet }, - group, - version, - resource, -) { - const namespace = getValue(model, '/metadata/namespace') - watchDependency('model#/metadata/namespace') - - let resources = await getNamespacedResourceList(axios, storeGet, { - namespace, - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + let resources = await getNamespacedResourceList(axios, storeGet, { + namespace, + group, + version, + resource, }) - } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) } - }) -} -async function unNamespacedResourceNames({ axios, storeGet }, group, version, resource) { - let resources = await getResourceList(axios, storeGet, { - group, - version, - resource, - }) - - if (resource === 'secrets') { - resources = resources.filter((item) => { - const validType = ['kubernetes.io/service-account-token', 'Opaque'] - return validType.includes(item.type) + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } }) } - return resources.map((resource) => { - const name = (resource.metadata && resource.metadata.name) || '' - return { - text: name, - value: name, - } - }) -} + async function unNamespacedResourceNames(group, version, resource) { + let resources = await getResourceList(axios, storeGet, { + group, + version, + resource, + }) -// reconfiguration type -function ifReconfigurationTypeEqualsTo({ discriminator, getValue, watchDependency }, value) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - watchDependency('discriminator#/reconfigurationType') + if (resource === 'secrets') { + resources = resources.filter((item) => { + const validType = ['kubernetes.io/service-account-token', 'Opaque'] + return validType.includes(item.type) + }) + } - return reconfigurationType === value -} + return resources.map((resource) => { + const name = (resource.metadata && resource.metadata.name) || '' + return { + text: name, + value: name, + } + }) + } -function onApplyconfigChange({ discriminator, getValue, commit }) { - const applyconfig = getValue(discriminator, '/applyConfig') + // reconfiguration type + function ifReconfigurationTypeEqualsTo(value) { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + // watchDependency'discriminator#/reconfigurationType') - const configObj = {} - if (applyconfig) { - applyconfig.forEach((item) => { - const { key, value } = item - configObj[key] = value - }) + return reconfigurationType === value } - commit('wizard/model$update', { - path: '/spec/configuration/applyConfig', - value: configObj, - force: true, - }) -} + function onApplyconfigChange() { + const applyconfig = getValue(discriminator, '/applyConfig') -function onReconfigurationTypeChange({ commit, discriminator, getValue, setDiscriminatorValue }) { - const reconfigurationType = getValue(discriminator, '/reconfigurationType') - setDiscriminatorValue('/applyConfig', []) - if (reconfigurationType === 'remove') { - commit('wizard/model$delete', `/spec/configuration`) + const configObj = {} + if (applyconfig) { + applyconfig.forEach((item) => { + const { key, value } = item + configObj[key] = value + }) + } commit('wizard/model$update', { - path: `/spec/configuration/removeCustomConfig`, - value: true, + path: '/spec/configuration/applyConfig', + value: configObj, force: true, }) - } else { - commit('wizard/model$delete', `/spec/configuration/configSecret`) - commit('wizard/model$delete', `/spec/configuration/applyConfig`) - commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) } -} - -function getRequestTypeFromRoute({ route, model, discriminator, getValue, watchDependency }) { - const isDbloading = isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) - const { query } = route || {} - const { requestType } = query || {} - return isDbloading ? '' : requestType || '' -} -// ************************************** Set db details ***************************************** + function onReconfigurationTypeChange() { + const reconfigurationType = getValue(discriminator, '/reconfigurationType') + setDiscriminatorValue('/applyConfig', []) + if (reconfigurationType === 'remove') { + commit('wizard/model$delete', `/spec/configuration`) -function isDbDetailsLoading({ discriminator, model, getValue, watchDependency }) { - watchDependency('discriminator#/dbDetails') - watchDependency('model#/spec/databaseRef/name') - const dbDetails = getValue(discriminator, '/dbDetails') - const dbName = getValue(model, '/spec/databaseRef/name') + commit('wizard/model$update', { + path: `/spec/configuration/removeCustomConfig`, + value: true, + force: true, + }) + } else { + commit('wizard/model$delete', `/spec/configuration/configSecret`) + commit('wizard/model$delete', `/spec/configuration/applyConfig`) + commit('wizard/model$delete', `/spec/configuration/removeCustomConfig`) + } + } - return !dbDetails || !dbName -} + function getRequestTypeFromRoute() { + const isDbloading = isDbDetailsLoading({ discriminator, model, getValue }) + const { query } = route || {} + const { requestType } = query || {} + return isDbloading ? '' : requestType || '' + } -function setValueFromDbDetails( - { discriminator, getValue, watchDependency, commit }, - path, - commitPath, -) { - watchDependency('discriminator#/dbDetails') + // ************************************** Set db details ***************************************** - const retValue = getValue(discriminator, `/dbDetails${path}`) + function isDbDetailsLoading() { + // watchDependency'discriminator#/dbDetails') + // watchDependency'model#/spec/databaseRef/name') + const dbDetails = getValue(discriminator, '/dbDetails') + const dbName = getValue(model, '/spec/databaseRef/name') - if (commitPath && retValue) { - const tlsOperation = getValue(discriminator, '/tlsOperation') + return !dbDetails || !dbName + } - // computed called when tls fields is not visible - if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined + function setValueFromDbDetails(path, commitPath) { + // watchDependency'discriminator#/dbDetails') - // direct model update required for reusable element. - // computed property is not applicable for reusable element - commit('wizard/model$update', { - path: commitPath, - value: retValue, - force: true, - }) - } + const retValue = getValue(discriminator, `/dbDetails${path}`) + console.log(retValue) - return retValue || undefined -} + if (commitPath && retValue) { + const tlsOperation = getValue(discriminator, '/tlsOperation') -function setResource({ discriminator, getValue, watchDependency }, path) { - watchDependency('discriminator#/dbDetails') - const containers = getValue(discriminator, `/dbDetails${path}`) || [] - const kind = getValue(discriminator, '/dbDetails/kind') - const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) - return resource[0].resources -} + // computed called when tls fields is not visible + if (commitPath.includes('/spec/tls') && tlsOperation !== 'update') return undefined -function isNamespaceDisabled({ route }) { - const { namespace } = route.query || {} - return !!namespace -} + // direct model update required for reusable element. + // computed property is not applicable for reusable element + commit('wizard/model$update', { + path: commitPath, + value: retValue, + force: true, + }) + } -function isDatabaseRefDisabled({ route }) { - const { name } = route.params || {} - return !!name -} + return retValue || undefined + } -function onNamespaceChange({ commit }) { - commit('wizard/model$delete', '/spec/type') -} + function setResource(path) { + // watchDependency'discriminator#/dbDetails') + const containers = getValue(discriminator, `/dbDetails${path}`) || [] + const kind = getValue(discriminator, '/dbDetails/kind') + const resource = containers.filter((ele) => ele.name === kind.toLowerCase()) + return resource[0].resources + } -function onDbChange({ commit, axios, storeGet, model, getValue, setDiscriminatorValue }) { - commit('wizard/model$delete', '/spec/type') - getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) -} + function isNamespaceDisabled() { + const { namespace } = route.query || {} + return !!namespace + } -function setApplyToIfReady() { - return 'IfReady' -} + function isDatabaseRefDisabled() { + const { name } = route.params || {} + return !!name + } -function isVerticalScaleTopologyRequired({ watchDependency, getValue, discriminator, commit }) { - watchDependency('discriminator#/topologyKey') - watchDependency('discriminator#/topologyValue') + function onNamespaceChange() { + commit('wizard/model$delete', '/spec/type') + } - const key = getValue(discriminator, '/topologyKey') - const value = getValue(discriminator, '/topologyValue') - const path = `/spec/verticalScaling/zookeeper/topology` + function onDbChange() { + commit('wizard/model$delete', '/spec/type') + getDbDetails({ axios, storeGet, model, getValue, setDiscriminatorValue }) + } - if (key || value) { - commit('wizard/model$update', { - path: path, - value: { key, value }, - force: true, - }) - return true - } else { - commit('wizard/model$delete', path) - return false + function setApplyToIfReady() { + return 'IfReady' } -} -// machine profile stuffs -let machinesFromPreset = [] + function isVerticalScaleTopologyRequired() { + // watchDependency'discriminator#/topologyKey') + // watchDependency'discriminator#/topologyValue') -function getMachines({ storeGet }) { - const presets = storeGet('/kubedbuiPresets') || {} - const avlMachines = presets.admin?.machineProfiles?.available || [] - let arr = [] - if (avlMachines.length) { - arr = avlMachines.map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - else { - const machineData = machinesFromPreset.find((val) => val.id === machine) - if (machineData) { - const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` - const text = machineData.name ? machineData.name : machineData.id - return { text, subText, value: machine } - } else return { text: machine, value: machine } - } - }) - } else { - arr = machineList - .map((machine) => { - if (machine === 'custom') return { text: machine, value: machine } - const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` - const text = machine - return { text, subText, value: machine } + const key = getValue(discriminator, '/topologyKey') + const value = getValue(discriminator, '/topologyValue') + const path = `/spec/verticalScaling/zookeeper/topology` + + if (key || value) { + commit('wizard/model$update', { + path: path, + value: { key, value }, + force: true, }) - .filter((val) => !!val) + return + } else { + commit('wizard/model$delete', path) + return false + } } - return arr -} -function setMachine({ getValue, discriminator, storeGet }) { - const dbDetails = getValue(discriminator, '/dbDetails') - const annotations = dbDetails?.metadata?.annotations || {} - const machine = annotations['kubernetes.io/instance-type'] || 'custom' + // machine profile stuffs + function getMachines() { + const presets = storeGet('/kubedbuiPresets') || {} + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = dbDetails?.spec?.podTemplate?.spec?.containers?.[0]?.resources?.requests + const avlMachines = presets.admin?.machineProfiles?.available || [] + let arr = [] + if (avlMachines.length) { + arr = avlMachines.map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + else { + const machineData = machinesFromPreset.find((val) => val.id === machine) + if (machineData) { + // const subText = `CPU: ${machineData.limits.cpu}, Memory: ${machineData.limits.memory}` + const text = machineData.name ? machineData.name : machineData.id + return { + text, + // subText, + value: { + machine: text, + cpu: machineData.limits.cpu, + memory: machineData.limits.memory, + }, + } + } else return { text: machine, value: { machine } } + } + }) + } else { + arr = machineList + .map((machine) => { + if (machine === 'custom') + return { text: machine, value: { machine, cpu: limits.cpu, memory: limits.memory } } + // const subText = `CPU: ${machines[machine].resources.limits.cpu}, Memory: ${machines[machine].resources.limits.memory}` + const text = machine + return { + text, + // subText, + value: { + machine: text, + cpu: machines[machine].resources.limits.cpu, + memory: machines[machine].resources.limits.memory, + }, + } + }) + .filter((val) => !!val) + } + return arr + } - machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] + function setMachine() { + const dbDetails = getValue(discriminator, '/dbDetails') + // const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {} + const limits = dbDetails?.spec?.podTemplate?.spec?.containers?.[0]?.resources?.requests + const annotations = dbDetails?.metadata?.annotations || {} + const machine = annotations['kubernetes.io/instance-type'] || 'custom' - const machinePresets = machinesFromPreset.find((item) => item.id === machine) - if (machinePresets) return machine - else return 'custom' -} + machinesFromPreset = storeGet('/kubedbuiPresets')?.admin?.machineProfiles?.machines || [] -function onMachineChange({ getValue, discriminator, commit, model }, type, valPath) { - let selectedMachine = '' - selectedMachine = getValue(discriminator, '/machine') - const machine = machinesFromPreset.find((item) => item.id === selectedMachine) - - let obj = {} - if (selectedMachine !== 'custom') { - if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } - else obj = machines[selectedMachine]?.resources - } else { - const val = getValue(discriminator, `/dbDetails${valPath}`) || {} - obj = Array.isArray(val) ? val[0]?.resources : { ...val } + const machinePresets = machinesFromPreset.find((item) => item.id === machine) + if (machinePresets) return machine + else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory } } - const path = `/spec/verticalScaling/${type}/resources` + function onMachineChange(type, valPath) { + let selectedMachine = '' + selectedMachine = getValue(discriminator, '/machine') + const machine = machinesFromPreset.find((item) => item.id === selectedMachine) + + let obj = {} + if (selectedMachine !== 'custom') { + if (machine) obj = { limits: { ...machine?.limits }, requests: { ...machine?.limits } } + else obj = machines[selectedMachine]?.resources + } else { + const val = getValue(discriminator, `/dbDetails${valPath}`) || {} + obj = Array.isArray(val) ? val[0]?.resources : { ...val } + } - if (obj && Object.keys(obj).length) - commit('wizard/model$update', { - path: path, - value: obj, - force: true, - }) + const path = `/spec/verticalScaling/${type}/resources` - // update metadata.annotations - const annotations = getValue(model, '/metadata/annotations') || {} - if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') - else { - annotations['kubernetes.io/instance-type'] = selectedMachine - if (machinesFromPreset.length) + if (obj && Object.keys(obj).length) commit('wizard/model$update', { - path: '/metadata/annotations', - value: annotations, + path: path, + value: obj, force: true, }) + + // update metadata.annotations + const annotations = getValue(model, '/metadata/annotations') || {} + if (selectedMachine === 'custom') commit('wizard/model$delete', '/metadata/annotations') + else { + annotations['kubernetes.io/instance-type'] = selectedMachine + if (machinesFromPreset.length) + commit('wizard/model$update', { + path: '/metadata/annotations', + value: annotations, + force: true, + }) + } } -} -function isMachineCustom({ watchDependency, getValue, discriminator }) { - watchDependency('discriminator#/machine') - const machine = getValue(discriminator, '/machine') - return machine === 'custom' -} + function isMachineCustom() { + // watchDependency'discriminator#/machine') + const machine = getValue(discriminator, '/machine') + return machine === 'custom' + } -function checkVolume({ model, discriminator, getValue }, initpath, path) { - const volume = getValue(discriminator, `/dbDetails${initpath}`) - const input = getValue(model, path) + function checkVolume(initpath, path) { + const volume = getValue(discriminator, `/dbDetails${initpath}`) + const input = getValue(model, path) - try { - const sizeInBytes = parseSize(volume) - const inputSizeInBytes = parseSize(input) + try { + const sizeInBytes = parseSize(volume) + const inputSizeInBytes = parseSize(input) - if (inputSizeInBytes >= sizeInBytes) return true - else return 'Cannot expand to lower volume!' - } catch (err) { - return err.message || 'Invalid' + if (inputSizeInBytes >= sizeInBytes) return + else return 'Cannot expand to lower volume!' + } catch (err) { + return err.message || 'Invalid' + } } -} -function parseSize(sizeStr) { - const units = { - '': 1, - K: 1e3, - M: 1e6, - G: 1e9, - T: 1e12, - P: 1e15, - E: 1e18, - Ki: 1024, - Mi: 1024 ** 2, - Gi: 1024 ** 3, - Ti: 1024 ** 4, - Pi: 1024 ** 5, - Ei: 1024 ** 6, - } + function parseSize(sizeStr) { + const units = { + '': 1, + K: 1e3, + M: 1e6, + G: 1e9, + T: 1e12, + P: 1e15, + E: 1e18, + Ki: 1024, + Mi: 1024 ** 2, + Gi: 1024 ** 3, + Ti: 1024 ** 4, + Pi: 1024 ** 5, + Ei: 1024 ** 6, + } - const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) - if (!match) throw new Error('Invalid size format') + const match = String(sizeStr).match(/^([0-9]+(?:\.[0-9]*)?)\s*([A-Za-z]*)$/) + if (!match) throw new Error('Invalid size format') - const value = parseFloat(match[1]) - const unit = match[2] + const value = parseFloat(match[1]) + const unit = match[2] - if (!(unit in units)) - throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') + if (!(unit in units)) + throw new Error('Unrecognized unit. Available units are K, Ki, M, Mi, G, Gi etc') - return value * units[unit] -} + return value * units[unit] + } -return { - returnFalse, - getNamespaces, - getDbs, - getDbDetails, - getDbVersions, - ifRequestTypeEqualsTo, - onRequestTypeChange, - getDbTls, - getDbType, - initNamespace, - initDatabaseRef, - isRancherManaged, - showAndInitName, - showAndInitNamespace, - showAndInitDatabaseRef, - showConfigureOpsrequestLabel, - showAndInitOpsRequestType, - - getConfigSecrets, - createSecretUrl, - isEqualToValueFromType, - disableOpsRequest, - getNamespacedResourceList, - getResourceList, - resourceNames, - unNamespacedResourceNames, - ifReconfigurationTypeEqualsTo, - onReconfigurationTypeChange, - onApplyconfigChange, - getRequestTypeFromRoute, - isDbDetailsLoading, - setValueFromDbDetails, - setResource, - isNamespaceDisabled, - isDatabaseRefDisabled, - onNamespaceChange, - onDbChange, - setApplyToIfReady, - isVerticalScaleTopologyRequired, - - getMachines, - setMachine, - onMachineChange, - isMachineCustom, - checkVolume, + return { + returnFalse, + getNamespaces, + getDbs, + getDbDetails, + getDbVersions, + ifRequestTypeEqualsTo, + onRequestTypeChange, + getDbTls, + getDbType, + initNamespace, + initDatabaseRef, + isRancherManaged, + showAndInitName, + showAndInitNamespace, + showAndInitDatabaseRef, + showConfigureOpsrequestLabel, + showAndInitOpsRequestType, + getConfigSecrets, + createSecretUrl, + isEqualToValueFromType, + disableOpsRequest, + getNamespacedResourceList, + getResourceList, + resourceNames, + unNamespacedResourceNames, + ifReconfigurationTypeEqualsTo, + onReconfigurationTypeChange, + onApplyconfigChange, + getRequestTypeFromRoute, + isDbDetailsLoading, + setValueFromDbDetails, + setResource, + isNamespaceDisabled, + isDatabaseRefDisabled, + onNamespaceChange, + onDbChange, + setApplyToIfReady, + isVerticalScaleTopologyRequired, + getMachines, + setMachine, + onMachineChange, + isMachineCustom, + checkVolume, + } } diff --git a/charts/storagekubestashcom-backupstorage-editor-options/ui/create-ui.yaml b/charts/storagekubestashcom-backupstorage-editor-options/ui/create-ui.yaml index 2164805b2b..51d9ac5ab2 100644 --- a/charts/storagekubestashcom-backupstorage-editor-options/ui/create-ui.yaml +++ b/charts/storagekubestashcom-backupstorage-editor-options/ui/create-ui.yaml @@ -1,287 +1,184 @@ -steps: -- form: - elements: +step: +- type: single-step-form + elements: + - loader: getNamespaces + hasGroup: isRancherManaged + label: Namespace + schema: schema/properties/metadata/properties/release/properties/namespace + type: select + - label: Name + schema: schema/properties/metadata/properties/release/properties/name + type: input + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + label: Labels & Annotations + showLabels: true + hideBlock: true + type: block-layout + - customClass: mt-20 + label: Deletion Policy + options: + - description: options.deletionPolicy.delete.description + text: Delete (Keep only database Secrets and backed up data) + value: Delete + - description: options.deletionPolicy.wipeOut.description + text: WipeOut (Delete everything including backed up data) + value: WipeOut + schema: schema/properties/spec/properties/deletionPolicy + type: select + - label: Security Context + schema: schema/properties/spec/properties/runtimeSettings/properties/securityContext + type: input + - elements: + - label: Provider + options: + - text: Azure + value: azure + - text: S3 + value: s3 + - text: GCS + value: gcs + - text: Local + value: local + init: + type: func + value: initBackendProvider + watcher: + func: onBackendProviderChange + paths: + - schema/properties/spec/properties/backend/properties/provider + schema: schema/properties/spec/properties/backend/properties/provider + type: select - elements: - - fetch: getNamespaces - hasGroup: isRancherManaged - label: - text: Namespace - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace - type: select - - label: - text: Name - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - elements: - - isArray: true - keys: - label: - text: Key - label: - text: Labels - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: Value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: Key - label: - text: Annotations - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: Value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - hideForm: true - label: - text: Labels & Annotations - show_label: true - type: single-step-form - - customClass: mt-20 - label: - text: Deletion Policy - options: - - description: options.deletionPolicy.delete.description - text: Delete (Keep only database Secrets and backed up data) - value: Delete - - description: options.deletionPolicy.wipeOut.description - text: WipeOut (Delete everything including backed up data) - value: WipeOut - schema: - $ref: schema#/properties/spec/properties/deletionPolicy - type: select - - label: - text: Security Context - schema: - $ref: schema#/properties/spec/properties/runtimeSettings/properties/securityContext + - label: Account Key + schema: schema/properties/spec/properties/backend/properties/azure/properties/auth/properties/AZURE_ACCOUNT_KEY + type: input + - label: Account Name + schema: schema/properties/spec/properties/backend/properties/azure/properties/auth/properties/AZURE_ACCOUNT_NAME + type: input + label: Auth + showLabels: true + type: block-layout + - elements: + - label: Container + schema: schema/properties/spec/properties/backend/properties/azure/properties/spec/properties/container + type: input + - label: Max Connections + schema: schema/properties/spec/properties/backend/properties/azure/properties/spec/properties/maxConnections + type: input + - label: Prefix + schema: schema/properties/spec/properties/backend/properties/azure/properties/spec/properties/prefix + type: input + label: Spec + showLabels: true + type: block-layout + if: + type: function + name: isProvider|azure + label: Azure + showLabels: true + type: block-layout + - elements: + - elements: + - label: Google Project ID + schema: schema/properties/spec/properties/backend/properties/gcs/properties/auth/properties/GOOGLE_PROJECT_ID + type: input + - label: Google Service Account JSON Key + schema: schema/properties/spec/properties/backend/properties/gcs/properties/auth/properties/GOOGLE_SERVICE_ACCOUNT_JSON_KEY + type: input + label: Auth + showLabels: true + type: block-layout + - elements: + - label: Bucket + schema: schema/properties/spec/properties/backend/properties/gcs/properties/spec/properties/bucket + type: input + - label: Max Connections + schema: schema/properties/spec/properties/backend/properties/gcs/properties/spec/properties/maxConnections + type: input + - label: Prefix + schema: schema/properties/spec/properties/backend/properties/gcs/properties/spec/properties/prefix + type: input + label: Spec + showLabels: true + type: block-layout + if: + type: function + name: isProvider|gcs + label: GCS + showLabels: true + type: block-layout + - elements: + - elements: + - label: AWS Access Key ID + schema: schema/properties/spec/properties/backend/properties/s3/properties/auth/properties/AWS_ACCESS_KEY_ID + type: input + - label: AWS Secret Access Key + schema: schema/properties/spec/properties/backend/properties/s3/properties/auth/properties/AWS_SECRET_ACCESS_KEY + type: input + - label: CA Cert Data + schema: schema/properties/spec/properties/backend/properties/s3/properties/auth/properties/CA_CERT_DATA + type: textarea + label: Auth + showLabels: true + type: block-layout + - elements: + - label: Insecure TLS + schema: schema/properties/spec/properties/backend/properties/s3/properties/spec/properties/insecureTLS + type: switch + - label: Bucket + schema: schema/properties/spec/properties/backend/properties/s3/properties/spec/properties/bucket + type: input + - label: End Point + schema: schema/properties/spec/properties/backend/properties/s3/properties/spec/properties/endpoint + type: input + - label: Prefix + schema: schema/properties/spec/properties/backend/properties/s3/properties/spec/properties/prefix + type: input + - label: Region + schema: schema/properties/spec/properties/backend/properties/s3/properties/spec/properties/region + type: input + label: Spec + showLabels: true + type: block-layout + if: + type: function + name: isProvider|s3 + label: S3 + showLabels: true + type: block-layout + - elements: + - label: Mount Path + schema: schema/properties/spec/properties/backend/properties/local/properties/mountPath + type: input + - label: Sub Path + schema: schema/properties/spec/properties/backend/properties/local/properties/subPath type: input - elements: - - label: - text: Provider - options: - - text: Azure - value: azure - - text: S3 - value: s3 - - text: GCS - value: gcs - - text: Local - value: local - schema: - $ref: schema#/properties/spec/properties/backend/properties/provider - type: select - - elements: - - elements: - - label: - text: Account Key - schema: - $ref: schema#/properties/spec/properties/backend/properties/azure/properties/auth/properties/AZURE_ACCOUNT_KEY - type: input - - label: - text: Account Name - schema: - $ref: schema#/properties/spec/properties/backend/properties/azure/properties/auth/properties/AZURE_ACCOUNT_NAME - type: input - label: - text: Auth - schema: - $ref: schema#/properties/spec/properties/backend/properties/azure/properties/auth - show_label: true - type: single-step-form - - elements: - - label: - text: Container - schema: - $ref: schema#/properties/spec/properties/backend/properties/azure/properties/spec/properties/container - type: input - - label: - text: Max Connections - schema: - $ref: schema#/properties/spec/properties/backend/properties/azure/properties/spec/properties/maxConnections - type: input - - label: - text: Prefix - schema: - $ref: schema#/properties/spec/properties/backend/properties/azure/properties/spec/properties/prefix - type: input - label: - text: Spec - schema: - $ref: schema#/properties/spec/properties/backend/properties/azure/properties/spec - show_label: true - type: single-step-form - if: isProvider|azure - label: - text: Azure - schema: - $ref: schema#/properties/spec/properties/backend/properties/azure - show_label: true - type: single-step-form - - elements: - - elements: - - label: - text: Google Project ID - schema: - $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/auth/properties/GOOGLE_PROJECT_ID - type: input - - label: - text: Google Service Account JSON Key - schema: - $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/auth/properties/GOOGLE_SERVICE_ACCOUNT_JSON_KEY - type: input - label: - text: Auth - schema: - $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/auth - show_label: true - type: single-step-form - - elements: - - label: - text: Bucket - schema: - $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/spec/properties/bucket - type: input - - label: - text: Max Connections - schema: - $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/spec/properties/maxConnections - type: input - - label: - text: Prefix - schema: - $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/spec/properties/prefix - type: input - label: - text: Spec - schema: - $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/spec - show_label: true - type: single-step-form - if: isProvider|gcs - label: - text: GCS - schema: - $ref: schema#/properties/spec/properties/backend/properties/gcs - show_label: true - type: single-step-form - - elements: - - elements: - - label: - text: AWS Access Key ID - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/auth/properties/AWS_ACCESS_KEY_ID - type: input - - label: - text: AWS Secret Access Key - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/auth/properties/AWS_SECRET_ACCESS_KEY - type: input - - label: - text: CA Cert Data - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/auth/properties/CA_CERT_DATA - type: textarea - label: - text: Auth - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/auth - show_label: true - type: single-step-form - - elements: - - label: - text: Insecure TLS - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/insecureTLS - type: switch - - label: - text: Bucket - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/bucket - type: input - - label: - text: End Point - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/endpoint - type: input - - label: - text: Prefix - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/prefix - type: input - - label: - text: Region - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/region - type: input - label: - text: Spec - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec - show_label: true - type: single-step-form - if: isProvider|s3 - label: - text: S3 - schema: - $ref: schema#/properties/spec/properties/backend/properties/s3 - show_label: true - type: single-step-form - - elements: - - label: - text: Mount Path - schema: - $ref: schema#/properties/spec/properties/backend/properties/local/properties/mountPath - type: input - - label: - text: Sub Path - schema: - $ref: schema#/properties/spec/properties/backend/properties/local/properties/subPath - type: input - - elements: - - label: - text: claim Name - schema: - $ref: schema#/properties/spec/properties/backend/properties/local/properties/persistentVolumeClaim/properties/claimName - type: input - - label: - text: ReadOnly? - schema: - $ref: schema#/properties/spec/properties/backend/properties/local/properties/persistentVolumeClaim/properties/readOnly - type: switch - label: - text: Persistent Volume Claim - schema: - $ref: schema#/properties/spec/properties/backend/properties/local/properties/persistentVolumeClaim - show_label: true - type: single-step-form - if: isProvider|local - label: - text: Local - schema: - $ref: schema#/properties/spec/properties/backend/properties/local - show_label: true - type: single-step-form - label: - text: Backend - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/spec - type: single-step-form - type: single-step-form + - label: claim Name + schema: schema/properties/spec/properties/backend/properties/local/properties/persistentVolumeClaim/properties/claimName + type: input + - label: ReadOnly? + schema: schema/properties/spec/properties/backend/properties/local/properties/persistentVolumeClaim/properties/readOnly + type: switch + label: Persistent Volume Claim + showLabels: true + type: block-layout + if: + type: function + name: isProvider|local + label: Local + showLabels: true + type: block-layout + label: Backend + showLabels: true + type: block-layout id: options - title: steps.0.label + # title: steps.0.label type: multi-step-form diff --git a/charts/storagekubestashcom-backupstorage-editor-options/ui/functions.js b/charts/storagekubestashcom-backupstorage-editor-options/ui/functions.js index 6e10409e34..f00073e8d2 100644 --- a/charts/storagekubestashcom-backupstorage-editor-options/ui/functions.js +++ b/charts/storagekubestashcom-backupstorage-editor-options/ui/functions.js @@ -1,140 +1,4 @@ -async function getResources( - { axios, storeGet, model, getValue, watchDependency }, - group, - version, - resource, - namespaced, -) { - const owner = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') - let namespace = '' - if (namespaced) { - namespace = getValue(model, '/metadata/release/namespace') - watchDependency('model#/metadata/release/namespace') - } - - if (!namespaced || namespace) { - // call api if resource is either not namespaced - // or namespaced and user has selected a namespace - try { - const resp = await axios.get( - `/clusters/${owner}/${cluster}/proxy/${group}/${version}${ - namespace ? '/namespaces/' + namespace : '' - }/${resource}`, - { - params: { filter: { items: { metadata: { name: null } } } }, - }, - ) - - const resources = (resp && resp.data && resp.data.items) || [] - - resources.map((item) => { - const name = (item.metadata && item.metadata.name) || '' - item.text = name - item.value = name - return true - }) - return resources - } catch (e) { - console.log(e) - return [] - } - } else return [] -} - -function initNamespace({ route }) { - const { namespace } = route.query || {} - return namespace || null -} -function isNamespaceDisabled({ route }) { - return !!initNamespace({ route }) || !isVariantAvailable -} - -function labelsDisabilityChecker({ itemCtx }) { - const { key } = itemCtx - if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true - else return false -} - -async function fetchJsons({ axios, itemCtx, setDiscriminatorValue }, discriminatorPath) { - let ui = {} - let language = {} - let functions = {} - const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart - try { - ui = await axios.get( - `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - language = await axios.get( - `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, - ) - const functionString = await axios.get( - `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, - ) - // declare evaluate the functionString to get the functions Object - const evalFunc = new Function(functionString.data || '') - functions = evalFunc() - } catch (e) { - console.log(e) - } - - if (discriminatorPath) { - setDiscriminatorValue(discriminatorPath, { - ui: ui.data || {}, - language: language.data || {}, - functions, - }) - } - - return { - ui: ui.data || {}, - language: language.data || {}, - functions, - } -} - -function showExistingSecretSelection({ discriminator, getValue, watchDependency }) { - const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') - const isExistingAuthSecretsFetching = getValue(discriminator, '/isExistingAuthSecretsFetching') - watchDependency('discriminator#/useExistingAuthSecret') - watchDependency('discriminator#/isExistingAuthSecretsFetching') - - return !isExistingAuthSecretsFetching && useExistingAuthSecret -} - -function onChoiseChange({ discriminator, getValue, commit }) { - const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') - // remove spec.storageSecret - commit('wizard/model$delete', '/spec/storageSecret') - if (useExistingAuthSecret) { - // remove the auth from each backend - Object.keys(backendMap).forEach((backend) => { - commit('wizard/model$delete', `/spec/backend/${backend}/auth`) - }) - } -} - -async function initExistingAuthSecrets(ctx) { - ctx.setDiscriminatorValue('/isExistingAuthSecretsFetching', true) - const secrets = await getResources(ctx, 'core', 'v1', 'secrets', true) - // set secrets; - ctx.setDiscriminatorValue('/existingAuthSecrets', secrets) - ctx.setDiscriminatorValue('/isExistingAuthSecretsFetching', false) - - return true -} - -async function getExistingAuthSecrets({ discriminator, getValue, watchDependency }) { - const existingAuthSecrets = getValue(discriminator, '/existingAuthSecrets') - watchDependency('discriminator#/existingAuthSecrets') - return existingAuthSecrets -} - -function showCreateSecretForm({ discriminator, getValue, watchDependency }) { - const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') - watchDependency('discriminator#/useExistingAuthSecret') - return !useExistingAuthSecret -} +const { ref, computed, axios, watch, useOperator, store } = window.vueHelpers || {} // backend configuration const backendMap = { @@ -179,144 +43,290 @@ const backendMap = { }, } -function initBackendProvider({ model, getValue }) { - const backend = getValue(model, '/spec/backend') - const selectedBackend = Object.keys(backendMap).find((key) => { - const value = backend && backend[key] +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) + + setDiscriminatorValue('useExistingAuthSecret', false) + setDiscriminatorValue('isExistingAuthSecretsFetching', false) + setDiscriminatorValue('existingAuthSecrets', []) + + async function getResources(group, version, resource, namespaced) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + let namespace = '' + if (namespaced) { + namespace = getValue(model, '/metadata/release/namespace') + // watchDependency('model#/metadata/release/namespace') + } - return value ? true : false - }) - return selectedBackend || 'gcs' -} + if (!namespaced || namespace) { + // call api if resource is either not namespaced + // or namespaced and user has selected a namespace + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}${ + namespace ? '/namespaces/' + namespace : '' + }/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } else return [] + } -function valueExists(value, getValue, path) { - const val = getValue(value, path) - if (val) return true - else return false -} + function initNamespace() { + const route = storeGet('/route') + const { namespace } = route.query || {} + return namespace || null + } + + function isNamespaceDisabled() { + const route = storeGet('/route') + return !!initNamespace() || !isVariantAvailable() + } + + function labelsDisabilityChecker(key) { + if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true + else return false + } + + async function fetchJsons(discriminatorPath) { + let ui = {} + let language = {} + let functions = {} + const itemCtx = storeGet('/itemCtx') + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } -function onBackendProviderChange({ commit, getValue, model }) { - const selectedBackendProvider = getValue(model, '/spec/backend/provider') + if (discriminatorPath) { + setDiscriminatorValue(discriminatorPath, { + ui: ui.data || {}, + language: language.data || {}, + functions, + }) + } - // delete every other backend type from model exect the selected one - Object.keys(backendMap).forEach((key) => { - if (key !== selectedBackendProvider) { - commit('wizard/model$delete', `/spec/backend/${key}`) + return { + ui: ui.data || {}, + language: language.data || {}, + functions, } - }) + } - // set the selectedBackend type object in + function showExistingSecretSelection() { + const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') + const isExistingAuthSecretsFetching = getValue(discriminator, '/isExistingAuthSecretsFetching') + // watchDependency('discriminator#/useExistingAuthSecret') + // watchDependency('discriminator#/isExistingAuthSecretsFetching') + + return !isExistingAuthSecretsFetching && useExistingAuthSecret + } - if (!valueExists(model, getValue, `/${selectedBackendProvider}`)) { - commit('wizard/model$update', { - path: `/spec/backend/${selectedBackendProvider}`, - value: {}, - force: true, + function onChoiseChange() { + const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') + // remove spec.storageSecret + commit('wizard/model$delete', '/spec/storageSecret') + if (useExistingAuthSecret) { + // remove the auth from each backend + Object.keys(backendMap).forEach((backend) => { + commit('wizard/model$delete', `/spec/backend/${backend}/auth`) + }) + } + } + + async function initExistingAuthSecrets() { + setDiscriminatorValue('/isExistingAuthSecretsFetching', true) + const secrets = await getResources('core', 'v1', 'secrets', true) + // set secrets; + setDiscriminatorValue('/existingAuthSecrets', secrets) + setDiscriminatorValue('/isExistingAuthSecretsFetching', false) + + return true + } + + async function getExistingAuthSecrets() { + const existingAuthSecrets = getValue(discriminator, '/existingAuthSecrets') + // watchDependency('discriminator#/existingAuthSecrets') + return existingAuthSecrets + } + + function showCreateSecretForm() { + const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') + // watchDependency('discriminator#/useExistingAuthSecret') + return !useExistingAuthSecret + } + + function initBackendProvider() { + const backend = getValue(model, '/spec/backend') + const selectedBackend = Object.keys(backendMap).find((key) => { + const value = backend && backend[key] + + return value ? true : false }) + return selectedBackend || 'gcs' } -} -function showBackendForm({ getValue, model, watchDependency }, value) { - const backendProvider = getValue(model, '/spec/backend/provider') - watchDependency('model#/spec/backend/provider') - return backendProvider === value -} + function valueExists(value, path) { + const val = getValue(value, path) + if (val) return true + else return false + } -function showSecretForm({ model, getValue, watchDependency }, value) { - const backendProvider = getValue(model, '/spec/backend/provider') - watchDependency('model#/spec/backend/provider') - return backendProvider === value -} + function onBackendProviderChange() { + const selectedBackendProvider = getValue(model, '/spec/backend/provider') -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + // delete every other backend type from model exect the selected one + Object.keys(backendMap).forEach((key) => { + if (key !== selectedBackendProvider) { + commit('wizard/model$delete', `/spec/backend/${key}`) + } + }) - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + // set the selectedBackend type object in + + if (!valueExists(model, `/${selectedBackendProvider}`)) { + commit('wizard/model$update', { + path: `/spec/backend/${selectedBackendProvider}`, + value: {}, + force: true, + }) + } } -} -function isVariantAvailable({ storeGet }) { - const variant = storeGet('/route/query/variant') - return variant ? true : false -} + function showBackendForm(value) { + const backendProvider = getValue(model, '/spec/backend/provider') + // watchDependency('model#/spec/backend/provider') + return backendProvider === value + } -async function getNamespaces({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], - }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace + function showSecretForm(value) { + const backendProvider = getValue(model, '/spec/backend/provider') + // watchDependency('model#/spec/backend/provider') + return backendProvider === value + } + + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` } else { - return resp.data?.status?.namespaces || [] + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` } - } catch (e) { - console.log(e) } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + function isVariantAvailable() { + const variant = storeGet('/route/query/variant') + return variant ? true : false + } -function isProvider({ watchDependency, model, getValue }, type) { - watchDependency('model#/spec/backend/provider') - const Provider = getValue(model, '/spec/backend/provider') - return type === Provider -} + async function getNamespaces() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] + } + + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } -return { - isRancherManaged, - isProvider, - getNamespaces, - isVariantAvailable, - getResources, - initNamespace, - isNamespaceDisabled, - labelsDisabilityChecker, - fetchJsons, - showExistingSecretSelection, - initExistingAuthSecrets, - onChoiseChange, - getExistingAuthSecrets, - showCreateSecretForm, - initBackendProvider, - onBackendProviderChange, - showBackendForm, - showSecretForm, - getCreateNameSpaceUrl, + function isProvider(type) { + // watchDependency('model#/spec/backend/provider') + const Provider = getValue(model, '/spec/backend/provider') + return type === Provider + } + + return { + isRancherManaged, + isProvider, + getNamespaces, + isVariantAvailable, + getResources, + initNamespace, + isNamespaceDisabled, + labelsDisabilityChecker, + fetchJsons, + showExistingSecretSelection, + initExistingAuthSecrets, + onChoiseChange, + getExistingAuthSecrets, + showCreateSecretForm, + initBackendProvider, + onBackendProviderChange, + showBackendForm, + showSecretForm, + getCreateNameSpaceUrl, + } } diff --git a/charts/storagekubestashcom-backupstorage-editor-options/ui/old.create-ui.yaml b/charts/storagekubestashcom-backupstorage-editor-options/ui/old.create-ui.yaml new file mode 100644 index 0000000000..2164805b2b --- /dev/null +++ b/charts/storagekubestashcom-backupstorage-editor-options/ui/old.create-ui.yaml @@ -0,0 +1,287 @@ +steps: +- form: + elements: + - elements: + - fetch: getNamespaces + hasGroup: isRancherManaged + label: + text: Namespace + schema: + $ref: schema#/properties/metadata/properties/release/properties/namespace + type: select + - label: + text: Name + schema: + $ref: schema#/properties/metadata/properties/release/properties/name + type: input + - elements: + - isArray: true + keys: + label: + text: Key + label: + text: Labels + schema: + $ref: schema#/properties/spec/properties/labels + type: key-value-input-form + values: + label: + text: Value + schema: + $ref: schema#/properties/spec/properties/labels/additionalProperties + type: input + - isArray: true + keys: + label: + text: Key + label: + text: Annotations + schema: + $ref: schema#/properties/spec/properties/annotations + type: key-value-input-form + values: + label: + text: Value + schema: + $ref: schema#/properties/spec/properties/annotations/additionalProperties + type: input + hideForm: true + label: + text: Labels & Annotations + show_label: true + type: single-step-form + - customClass: mt-20 + label: + text: Deletion Policy + options: + - description: options.deletionPolicy.delete.description + text: Delete (Keep only database Secrets and backed up data) + value: Delete + - description: options.deletionPolicy.wipeOut.description + text: WipeOut (Delete everything including backed up data) + value: WipeOut + schema: + $ref: schema#/properties/spec/properties/deletionPolicy + type: select + - label: + text: Security Context + schema: + $ref: schema#/properties/spec/properties/runtimeSettings/properties/securityContext + type: input + - elements: + - label: + text: Provider + options: + - text: Azure + value: azure + - text: S3 + value: s3 + - text: GCS + value: gcs + - text: Local + value: local + schema: + $ref: schema#/properties/spec/properties/backend/properties/provider + type: select + - elements: + - elements: + - label: + text: Account Key + schema: + $ref: schema#/properties/spec/properties/backend/properties/azure/properties/auth/properties/AZURE_ACCOUNT_KEY + type: input + - label: + text: Account Name + schema: + $ref: schema#/properties/spec/properties/backend/properties/azure/properties/auth/properties/AZURE_ACCOUNT_NAME + type: input + label: + text: Auth + schema: + $ref: schema#/properties/spec/properties/backend/properties/azure/properties/auth + show_label: true + type: single-step-form + - elements: + - label: + text: Container + schema: + $ref: schema#/properties/spec/properties/backend/properties/azure/properties/spec/properties/container + type: input + - label: + text: Max Connections + schema: + $ref: schema#/properties/spec/properties/backend/properties/azure/properties/spec/properties/maxConnections + type: input + - label: + text: Prefix + schema: + $ref: schema#/properties/spec/properties/backend/properties/azure/properties/spec/properties/prefix + type: input + label: + text: Spec + schema: + $ref: schema#/properties/spec/properties/backend/properties/azure/properties/spec + show_label: true + type: single-step-form + if: isProvider|azure + label: + text: Azure + schema: + $ref: schema#/properties/spec/properties/backend/properties/azure + show_label: true + type: single-step-form + - elements: + - elements: + - label: + text: Google Project ID + schema: + $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/auth/properties/GOOGLE_PROJECT_ID + type: input + - label: + text: Google Service Account JSON Key + schema: + $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/auth/properties/GOOGLE_SERVICE_ACCOUNT_JSON_KEY + type: input + label: + text: Auth + schema: + $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/auth + show_label: true + type: single-step-form + - elements: + - label: + text: Bucket + schema: + $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/spec/properties/bucket + type: input + - label: + text: Max Connections + schema: + $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/spec/properties/maxConnections + type: input + - label: + text: Prefix + schema: + $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/spec/properties/prefix + type: input + label: + text: Spec + schema: + $ref: schema#/properties/spec/properties/backend/properties/gcs/properties/spec + show_label: true + type: single-step-form + if: isProvider|gcs + label: + text: GCS + schema: + $ref: schema#/properties/spec/properties/backend/properties/gcs + show_label: true + type: single-step-form + - elements: + - elements: + - label: + text: AWS Access Key ID + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/auth/properties/AWS_ACCESS_KEY_ID + type: input + - label: + text: AWS Secret Access Key + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/auth/properties/AWS_SECRET_ACCESS_KEY + type: input + - label: + text: CA Cert Data + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/auth/properties/CA_CERT_DATA + type: textarea + label: + text: Auth + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/auth + show_label: true + type: single-step-form + - elements: + - label: + text: Insecure TLS + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/insecureTLS + type: switch + - label: + text: Bucket + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/bucket + type: input + - label: + text: End Point + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/endpoint + type: input + - label: + text: Prefix + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/prefix + type: input + - label: + text: Region + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec/properties/region + type: input + label: + text: Spec + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3/properties/spec + show_label: true + type: single-step-form + if: isProvider|s3 + label: + text: S3 + schema: + $ref: schema#/properties/spec/properties/backend/properties/s3 + show_label: true + type: single-step-form + - elements: + - label: + text: Mount Path + schema: + $ref: schema#/properties/spec/properties/backend/properties/local/properties/mountPath + type: input + - label: + text: Sub Path + schema: + $ref: schema#/properties/spec/properties/backend/properties/local/properties/subPath + type: input + - elements: + - label: + text: claim Name + schema: + $ref: schema#/properties/spec/properties/backend/properties/local/properties/persistentVolumeClaim/properties/claimName + type: input + - label: + text: ReadOnly? + schema: + $ref: schema#/properties/spec/properties/backend/properties/local/properties/persistentVolumeClaim/properties/readOnly + type: switch + label: + text: Persistent Volume Claim + schema: + $ref: schema#/properties/spec/properties/backend/properties/local/properties/persistentVolumeClaim + show_label: true + type: single-step-form + if: isProvider|local + label: + text: Local + schema: + $ref: schema#/properties/spec/properties/backend/properties/local + show_label: true + type: single-step-form + label: + text: Backend + show_label: true + type: single-step-form + schema: + $ref: schema#/properties/spec + type: single-step-form + type: single-step-form + id: options + title: steps.0.label +type: multi-step-form diff --git a/charts/storagekubestashcom-backupstorage-editor-options/ui/old.functions.js b/charts/storagekubestashcom-backupstorage-editor-options/ui/old.functions.js new file mode 100644 index 0000000000..6e10409e34 --- /dev/null +++ b/charts/storagekubestashcom-backupstorage-editor-options/ui/old.functions.js @@ -0,0 +1,322 @@ +async function getResources( + { axios, storeGet, model, getValue, watchDependency }, + group, + version, + resource, + namespaced, +) { + const owner = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + let namespace = '' + if (namespaced) { + namespace = getValue(model, '/metadata/release/namespace') + watchDependency('model#/metadata/release/namespace') + } + + if (!namespaced || namespace) { + // call api if resource is either not namespaced + // or namespaced and user has selected a namespace + try { + const resp = await axios.get( + `/clusters/${owner}/${cluster}/proxy/${group}/${version}${ + namespace ? '/namespaces/' + namespace : '' + }/${resource}`, + { + params: { filter: { items: { metadata: { name: null } } } }, + }, + ) + + const resources = (resp && resp.data && resp.data.items) || [] + + resources.map((item) => { + const name = (item.metadata && item.metadata.name) || '' + item.text = name + item.value = name + return true + }) + return resources + } catch (e) { + console.log(e) + return [] + } + } else return [] +} + +function initNamespace({ route }) { + const { namespace } = route.query || {} + return namespace || null +} +function isNamespaceDisabled({ route }) { + return !!initNamespace({ route }) || !isVariantAvailable +} + +function labelsDisabilityChecker({ itemCtx }) { + const { key } = itemCtx + if (key.startsWith('app.kubernetes.io') || key.includes('helm')) return true + else return false +} + +async function fetchJsons({ axios, itemCtx, setDiscriminatorValue }, discriminatorPath) { + let ui = {} + let language = {} + let functions = {} + const { name, sourceRef, version, packageviewUrlPrefix } = itemCtx.chart + try { + ui = await axios.get( + `${packageviewUrlPrefix}/create-ui.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + language = await axios.get( + `${packageviewUrlPrefix}/language.yaml?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}&format=json`, + ) + const functionString = await axios.get( + `${packageviewUrlPrefix}/functions.js?name=${name}&sourceApiGroup=${sourceRef.apiGroup}&sourceKind=${sourceRef.kind}&sourceNamespace=${sourceRef.namespace}&sourceName=${sourceRef.name}&version=${version}`, + ) + // declare evaluate the functionString to get the functions Object + const evalFunc = new Function(functionString.data || '') + functions = evalFunc() + } catch (e) { + console.log(e) + } + + if (discriminatorPath) { + setDiscriminatorValue(discriminatorPath, { + ui: ui.data || {}, + language: language.data || {}, + functions, + }) + } + + return { + ui: ui.data || {}, + language: language.data || {}, + functions, + } +} + +function showExistingSecretSelection({ discriminator, getValue, watchDependency }) { + const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') + const isExistingAuthSecretsFetching = getValue(discriminator, '/isExistingAuthSecretsFetching') + watchDependency('discriminator#/useExistingAuthSecret') + watchDependency('discriminator#/isExistingAuthSecretsFetching') + + return !isExistingAuthSecretsFetching && useExistingAuthSecret +} + +function onChoiseChange({ discriminator, getValue, commit }) { + const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') + // remove spec.storageSecret + commit('wizard/model$delete', '/spec/storageSecret') + if (useExistingAuthSecret) { + // remove the auth from each backend + Object.keys(backendMap).forEach((backend) => { + commit('wizard/model$delete', `/spec/backend/${backend}/auth`) + }) + } +} + +async function initExistingAuthSecrets(ctx) { + ctx.setDiscriminatorValue('/isExistingAuthSecretsFetching', true) + const secrets = await getResources(ctx, 'core', 'v1', 'secrets', true) + // set secrets; + ctx.setDiscriminatorValue('/existingAuthSecrets', secrets) + ctx.setDiscriminatorValue('/isExistingAuthSecretsFetching', false) + + return true +} + +async function getExistingAuthSecrets({ discriminator, getValue, watchDependency }) { + const existingAuthSecrets = getValue(discriminator, '/existingAuthSecrets') + watchDependency('discriminator#/existingAuthSecrets') + return existingAuthSecrets +} + +function showCreateSecretForm({ discriminator, getValue, watchDependency }) { + const useExistingAuthSecret = getValue(discriminator, '/useExistingAuthSecret') + watchDependency('discriminator#/useExistingAuthSecret') + return !useExistingAuthSecret +} + +// backend configuration +const backendMap = { + azure: { + spec: { container: '', maxConnections: 0, prefix: '' }, + auth: { AZURE_ACCOUNT_KEY: '', AZURE_ACCOUNT_NAME: '' }, + }, + b2: { + spec: { bucket: '', prefix: '', maxConnections: 0 }, + auth: { B2_ACCOUNT_ID: '', B2_ACCOUNT_KEY: '' }, + }, + gcs: { + spec: { bucket: '', prefix: '', maxConnections: 0 }, + auth: { GOOGLE_PROJECT_ID: '', GOOGLE_SERVICE_ACCOUNT_JSON_KEY: '' }, + }, + s3: { + spec: { endpoint: '', bucket: '', prefix: '', region: '' }, + auth: { + AWS_ACCESS_KEY_ID: '', + AWS_SECRET_ACCESS_KEY: '', + CA_CERT_DATA: '', + }, + }, + swift: { + spec: { container: '', prefix: '' }, + auth: { + OS_AUTH_TOKEN: '', + OS_AUTH_URL: '', + OS_PASSWORD: '', + OS_PROJECT_DOMAIN_NAME: '', + OS_PROJECT_NAME: '', + OS_REGION_NAME: '', + OS_STORAGE_URL: '', + OS_TENANT_ID: '', + OS_TENANT_NAME: '', + OS_USERNAME: '', + OS_USER_DOMAIN_NAME: '', + ST_AUTH: '', + ST_KEY: '', + ST_USER: '', + }, + }, +} + +function initBackendProvider({ model, getValue }) { + const backend = getValue(model, '/spec/backend') + const selectedBackend = Object.keys(backendMap).find((key) => { + const value = backend && backend[key] + + return value ? true : false + }) + return selectedBackend || 'gcs' +} + +function valueExists(value, getValue, path) { + const val = getValue(value, path) + if (val) return true + else return false +} + +function onBackendProviderChange({ commit, getValue, model }) { + const selectedBackendProvider = getValue(model, '/spec/backend/provider') + + // delete every other backend type from model exect the selected one + Object.keys(backendMap).forEach((key) => { + if (key !== selectedBackendProvider) { + commit('wizard/model$delete', `/spec/backend/${key}`) + } + }) + + // set the selectedBackend type object in + + if (!valueExists(model, getValue, `/${selectedBackendProvider}`)) { + commit('wizard/model$update', { + path: `/spec/backend/${selectedBackendProvider}`, + value: {}, + force: true, + }) + } +} + +function showBackendForm({ getValue, model, watchDependency }, value) { + const backendProvider = getValue(model, '/spec/backend/provider') + watchDependency('model#/spec/backend/provider') + return backendProvider === value +} + +function showSecretForm({ model, getValue, watchDependency }, value) { + const backendProvider = getValue(model, '/spec/backend/provider') + watchDependency('model#/spec/backend/provider') + return backendProvider === value +} + +function getCreateNameSpaceUrl({ model, getValue, storeGet }) { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } +} + +function isVariantAvailable({ storeGet }) { + const variant = storeGet('/route/query/variant') + return variant ? true : false +} + +async function getNamespaces({ axios, storeGet }) { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] +} + +function isRancherManaged({ storeGet }) { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found +} + +function isProvider({ watchDependency, model, getValue }, type) { + watchDependency('model#/spec/backend/provider') + const Provider = getValue(model, '/spec/backend/provider') + return type === Provider +} + +return { + isRancherManaged, + isProvider, + getNamespaces, + isVariantAvailable, + getResources, + initNamespace, + isNamespaceDisabled, + labelsDisabilityChecker, + fetchJsons, + showExistingSecretSelection, + initExistingAuthSecrets, + onChoiseChange, + getExistingAuthSecrets, + showCreateSecretForm, + initBackendProvider, + onBackendProviderChange, + showBackendForm, + showSecretForm, + getCreateNameSpaceUrl, +} diff --git a/charts/storagekubestashcom-repository-editor-options/ui/create-ui.yaml b/charts/storagekubestashcom-repository-editor-options/ui/create-ui.yaml index 4dbb2a9289..538c45da7b 100644 --- a/charts/storagekubestashcom-repository-editor-options/ui/create-ui.yaml +++ b/charts/storagekubestashcom-repository-editor-options/ui/create-ui.yaml @@ -1,169 +1,108 @@ -steps: -- form: - discriminator: - nameSpaceApi: - default: false - type: boolean - elements: - - computed: init - if: returnFalse +step: +- type: single-step-form + loader: init + elements: + - elements: + - loader: getNamespacesApi + hasGroup: isRancherManaged + label: Namespace + schema: schema/properties/metadata/properties/release/properties/namespace + type: select + - label: Repository Name + schema: schema/properties/metadata/properties/release/properties/name type: input + type: block-layout + - elements: + - type: object-item + label: Labels + schema: schema/properties/spec/properties/labels + - type: object-item + label: Annotations + schema: schema/properties/spec/properties/annotations + - label: Deletion Policy + options: + - Delete + - WipeOut + schema: schema/properties/spec/properties/deletionPolicy + type: select - elements: - - fetch: getNamespacesApi + - disableUnselect: true + loader: fetchNamespaces hasGroup: isRancherManaged - label: - text: labels.namespace - schema: - $ref: schema#/properties/metadata/properties/release/properties/namespace + label: Namespace + refresh: true + watcher: + func: onStorageRefNamespaceChange + paths: + - schema/properties/spec/properties/storageRef/properties/namespace + schema: schema/properties/spec/properties/storageRef/properties/namespace type: select - - label: - text: labels.repository.name - schema: - $ref: schema#/properties/metadata/properties/release/properties/name - type: input - schema: - $ref: schema#/properties/metadata/properties/release - type: single-step-form - - discriminator: - existingAuthSecrets: - default: [] - type: Array - isExistingAuthSecretsFetching: - default: true - type: boolean - useExistingAuthSecret: - default: true - type: boolean - elements: - - isArray: true - keys: - label: - text: labels.key - label: - text: labels.repository.labels - schema: - $ref: schema#/properties/spec/properties/labels - type: key-value-input-form - values: - label: - text: labels.value - schema: - $ref: schema#/properties/spec/properties/labels/additionalProperties - type: input - - isArray: true - keys: - label: - text: labels.key - label: - text: labels.repository.annotations - schema: - $ref: schema#/properties/spec/properties/annotations - type: key-value-input-form - values: - label: - text: labels.value - schema: - $ref: schema#/properties/spec/properties/annotations/additionalProperties - type: input - - label: - text: Deletion Policy - options: - - Delete - - WipeOut - schema: - $ref: schema#/properties/spec/properties/deletionPolicy + - disableUnselect: true + loader: fetchNames|storageRef + label: Name + refresh: true + schema: schema/properties/spec/properties/storageRef/properties/name type: select - - elements: - - disableUnselect: true - fetch: fetchNamespaces - hasGroup: isRancherManaged - label: - text: labels.namespace - refresh: true - schema: - $ref: schema#/properties/spec/properties/storageRef/properties/namespace - type: select - - disableUnselect: true - fetch: fetchNames|storageRef - label: - text: labels.name - refresh: true - schema: - $ref: schema#/properties/spec/properties/storageRef/properties/name - type: select - label: - text: labels.storageRef - schema: - $ref: schema#/properties/spec/properties/storageRef - show_label: true - type: single-step-form - - elements: - - disableUnselect: true - fetch: fetchNamespaces - hasGroup: isRancherManaged - label: - text: labels.namespace - refresh: true - schema: - $ref: schema#/properties/spec/properties/encryptionSecret/properties/namespace - type: select - - disableUnselect: true - fetch: fetchNames|encryptionSecret - label: - text: labels.name - refresh: true - schema: - $ref: schema#/properties/spec/properties/encryptionSecret/properties/name - type: select - label: - text: labels.encryptionSecret - schema: - $ref: schema#/properties/spec/properties/encryptionSecret - show_label: true - type: single-step-form - - label: - text: Path - schema: - $ref: schema#/properties/spec/properties/path - type: input - - elements: - - fetch: getApiGroup - label: - text: Api Group - schema: - $ref: schema#/properties/spec/properties/appRef/properties/apiGroup - type: select - - fetch: getKinds - label: - text: Kind - onChange: setVersion - schema: - $ref: schema#/properties/spec/properties/appRef/properties/kind - sortable: true - type: select - - fetch: fetchNamespaces - hasGroup: isRancherManaged - label: - text: Namespace - schema: - $ref: schema#/properties/spec/properties/appRef/properties/namespace - type: select - - fetch: getTargetName - label: - text: Name - schema: - $ref: schema#/properties/spec/properties/appRef/properties/name - type: select - label: - text: App Ref - schema: - $ref: schema#/properties/spec/properties/appRef - show_label: true - type: single-step-form - schema: - $ref: schema#/properties/spec - type: single-step-form - type: single-step-form + label: Storage Ref + showLabels: true + type: block-layout + - elements: + - disableUnselect: true + loader: fetchNamespaces + hasGroup: isRancherManaged + label: Namespace + refresh: true + watcher: + func: onEncryptionSecretNamespaceChange + paths: + - schema/properties/spec/properties/encryptionSecret/properties/namespace + schema: schema/properties/spec/properties/encryptionSecret/properties/namespace + type: select + - disableUnselect: true + loader: fetchNames|encryptionSecret + label: Name + refresh: true + schema: schema/properties/spec/properties/encryptionSecret/properties/name + type: select + label: Encryption Secret + showLabels: true + type: block-layout + - label: Path + schema: schema/properties/spec/properties/path + type: input + - elements: + - loader: getApiGroup + label: Api Group + watcher: + func: onApiGroupChange + paths: + - schema/properties/spec/properties/appRef/properties/apiGroup + schema: schema/properties/spec/properties/appRef/properties/apiGroup + type: select + - loader: getKinds + label: Kind + watcher: + func: setVersion + paths: + - schema/properties/spec/properties/appRef/properties/kind + schema: schema/properties/spec/properties/appRef/properties/kind + type: select + - loader: fetchNamespaces + hasGroup: isRancherManaged + label: Namespace + watcher: + func: onAppRefNamespaceChange + paths: + - schema/properties/spec/properties/appRef/properties/namespace + schema: schema/properties/spec/properties/appRef/properties/namespace + type: select + - loader: getTargetName + label: Name + schema: schema/properties/spec/properties/appRef/properties/name + type: select + label: App Ref + showLabels: true + type: block-layout + type: block-layout id: options - title: steps.0.label type: multi-step-form diff --git a/charts/storagekubestashcom-repository-editor-options/ui/functions.js b/charts/storagekubestashcom-repository-editor-options/ui/functions.js index 01c87284b4..abf5d6bcb1 100644 --- a/charts/storagekubestashcom-repository-editor-options/ui/functions.js +++ b/charts/storagekubestashcom-repository-editor-options/ui/functions.js @@ -1,3 +1,5 @@ +const { axios, store } = window.vueHelpers || {} + let namespaces = [] let appKind = [] let coreKind = [] @@ -6,237 +8,303 @@ let availableKinds = {} let kindToResourceMap = {} let version = '' -function init({ watchDependency, model, getValue, storeGet, axios, setDiscriminatorValue }) { - namespaces = getNamespacesApi({ axios, storeGet }) - getKindsApi({ watchDependency, model, getValue, storeGet, axios }) - setDiscriminatorValue('/nameSpaceApi', true) -} +export const useFunc = (model) => { + const { getValue, setDiscriminatorValue, commit, storeGet, discriminator } = useOperator( + model, + store.state, + ) -function getKinds({ watchDependency, getValue, model }) { - watchDependency(`model#/spec/appRef/apiGroup`) - const apiGroup = getValue(model, `/spec/appRef/apiGroup`) - console.log(apiGroup) + setDiscriminatorValue('nameSpaceApi', false) + setDiscriminatorValue('existingAuthSecrets', []) + setDiscriminatorValue('isExistingAuthSecretsFetching', true) + setDiscriminatorValue('useExistingAuthSecret', true) - if (apiGroup === 'core') return coreKind - else if (apiGroup === 'apps') return appKind - else return kubedbKind -} + async function init() { + namespaces = await getNamespacesApi() + await getKindsApi() + setDiscriminatorValue('/nameSpaceApi', true) + } -function setVersion({ getValue, model }) { - let apiGroup = getValue(model, `/spec/appRef/apiGroup`) - const kind = getValue(model, `/spec/appRef/kind`) - if (apiGroup === 'core') apiGroup = '' - console.log(availableKinds) + function getKinds() { + // watchDependency(`model#/spec/appRef/apiGroup`) + const apiGroup = getValue(model, `/spec/appRef/apiGroup`) - Object.keys(availableKinds[apiGroup]).forEach((vs) => { - availableKinds[apiGroup][vs].forEach((ele) => { - if (ele.Kind === kind) { - version = vs - } - }) - }) -} + if (apiGroup === 'core') return coreKind + else if (apiGroup === 'apps') return appKind + else return kubedbKind + } -async function getKindsApi({ storeGet, axios }) { - const params = storeGet('/route/params') - const { user, cluster } = params - let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` - try { - const resp = await axios.get(url) - - kindToResourceMap['kubedb.com'] = {} - kindToResourceMap['apps'] = {} - kindToResourceMap['core'] = {} - - availableKinds = resp.data - appKind = Object.values(availableKinds['apps']) - .flat() - .map((ele) => { - kindToResourceMap['apps'][ele.Kind] = ele.Resource - return ele.Kind - }) - kubedbKind = Object.values(availableKinds['kubedb.com']) - .flat() - .map((ele) => { - kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource - return ele.Kind - }) - coreKind = Object.values(availableKinds['']) - .flat() - .map((ele) => { - kindToResourceMap['core'][ele.Kind] = ele.Resource - return ele.Kind + function setVersion() { + let apiGroup = getValue(model, `/spec/appRef/apiGroup`) + const kind = getValue(model, `/spec/appRef/kind`) + if (apiGroup === 'core') apiGroup = '' + + Object.keys(availableKinds[apiGroup]).forEach((vs) => { + availableKinds[apiGroup][vs].forEach((ele) => { + if (ele.Kind === kind) { + version = vs + } }) - } catch (e) { - console.log(e) + }) } - return [] -} -function isRancherManaged({ storeGet }) { - const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') - const found = managers.find((item) => item === 'Rancher') - return !!found -} + async function getKindsApi() { + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` + try { + const resp = await axios.get(url) -function fetchNamespaces({ watchDependency }) { - watchDependency('discriminator#/nameSpaceApi') - return namespaces -} -async function getNamespacesApi({ axios, storeGet }) { - const params = storeGet('/route/params') - const { user, cluster, group, version, resource } = params - try { - const resp = await axios.post( - `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, - { - apiVersion: 'identity.k8s.appscode.com/v1alpha1', - kind: 'SelfSubjectNamespaceAccessReview', - spec: { - resourceAttributes: [ - { - verb: 'create', - group: group, - version: version, - resource: resource, - }, - ], + kindToResourceMap['kubedb.com'] = {} + kindToResourceMap['apps'] = {} + kindToResourceMap['core'] = {} + + availableKinds = resp.data + appKind = Object.values(availableKinds['apps']) + .flat() + .map((ele) => { + kindToResourceMap['apps'][ele.Kind] = ele.Resource + return ele.Kind + }) + kubedbKind = Object.values(availableKinds['kubedb.com']) + .flat() + .map((ele) => { + kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource + return ele.Kind + }) + coreKind = Object.values(availableKinds['']) + .flat() + .map((ele) => { + kindToResourceMap['core'][ele.Kind] = ele.Resource + return ele.Kind + }) + } catch (e) { + console.log(e) + } + return [] + } + + function isRancherManaged() { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found + } + + function fetchNamespaces() { + // watchDependency('discriminator#/nameSpaceApi') + return namespaces + } + + async function getNamespacesApi() { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, }, - }, - ) - if (resp.data?.status?.projects) { - const projects = resp.data?.status?.projects - let projectsNamespace = [] - projectsNamespace = Object.keys(projects).map((project) => ({ - project: project, - namespaces: projects[project].map((namespace) => ({ - text: namespace, - value: namespace, - })), - })) - return projectsNamespace - } else { - return resp.data?.status?.namespaces || [] + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) } - } catch (e) { - console.log(e) + return [] } - return [] -} -async function fetchNames({ getValue, model, storeGet, watchDependency, axios }, type) { - watchDependency(`model#/spec/${type}/namespace`) || '' - const user = storeGet('/route/params/user') || '' - const cluster = storeGet('/route/params/cluster') || '' - const namespace = getValue(model, `/spec/${type}/namespace`) || '' - let suffix = type - if (type === 'encryptionSecret') suffix = 'secrets' - else if (type === 'repository') suffix = 'repositories' - else if (type === 'storageRef') suffix = 'backupstorages' - const core = suffix === 'secrets' ? 'core' : 'storage.kubestash.com' - const version = suffix === 'secrets' ? 'v1' : 'v1alpha1' - const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/${suffix}` - - try { - if (namespace) { - const resp = await axios.get(url) - let names = resp?.data?.items - names.map((item) => { - item.value = item?.metadata?.name || '' - item.text = item?.metadata?.name || '' - return true - }) + async function fetchNames(type) { + // watchDependency(`model#/spec/${type}/namespace`) + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = getValue(model, `/spec/${type}/namespace`) || '' + let suffix = type + if (type === 'encryptionSecret') suffix = 'secrets' + else if (type === 'repository') suffix = 'repositories' + else if (type === 'storageRef') suffix = 'backupstorages' + const core = suffix === 'secrets' ? 'core' : 'storage.kubestash.com' + const version = suffix === 'secrets' ? 'v1' : 'v1alpha1' + const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/${suffix}` - if (type === 'repository') { - const resource = storeGet('/resource/layout/result/resource') || {} - let group = resource?.group || '' - let kind = resource?.kind || '' + try { + if (namespace) { + const resp = await axios.get(url) + let names = resp?.data?.items + names.map((item) => { + item.value = item?.metadata?.name || '' + item.text = item?.metadata?.name || '' + return true + }) - if (isConsole({ storeGet })) { - group = getValue(model, '/spec/appRef/apiGroup') || '' - kind = getValue(model, '/spec/appRef/kind') || '' + if (type === 'repository') { + const resource = storeGet('/resource/layout/result/resource') || {} + let group = resource?.group || '' + let kind = resource?.kind || '' + + if (isConsole()) { + group = getValue(model, '/spec/appRef/apiGroup') || '' + kind = getValue(model, '/spec/appRef/kind') || '' + } + + const filteredRepo = names.filter((item) => { + const appRef = item?.spec?.appRef || {} + return appRef?.apiGroup === group && appRef?.kind === kind + }) + return filteredRepo } + return names + } + } catch (e) { + console.log(e) + } + return [] + } + + function isConsole() { + const urlPrefix = storeGet('/route/params/urlPrefix') || '' + return urlPrefix.includes('console') + } + + function getCreateNameSpaceUrl() { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') - const filteredRepo = names.filter((item) => { - const appRef = item?.spec?.appRef || {} - return appRef?.apiGroup === group && appRef?.kind === kind + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } + } + + function getApiGroup() { + return ['core', 'apps', 'kubedb.com'] + } + + async function getTargetName() { + // watchDependency('model#/spec/appRef/apiGroup') + // watchDependency('model#/spec/appRef/namespace') + // watchDependency('model#/spec/appRef/kind') + const apiGroup = getValue(model, `/spec/appRef/apiGroup`) + const namespace = getValue(model, `/spec/appRef/namespace`) + const resource = getResourceName() + const params = storeGet('/route/params') + const { user, cluster } = params + + const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` + if (apiGroup && version && resource && namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + const options = items.map((ele) => { + return ele.metadata.name }) - return filteredRepo + return options + } catch (e) { + console.log(e) } - return names } - } catch (e) { - console.log(e) + return [] } - return [] -} -function getCreateNameSpaceUrl({ model, getValue, storeGet }) { - const user = storeGet('/route/params/user') - const cluster = storeGet('/route/params/cluster') + function getResourceName() { + const apiGroup = getValue(model, `/spec/appRef/apiGroup`) + const kind = getValue(model, `/spec/appRef/kind`) + if (!kind || !apiGroup) return '' + return kindToResourceMap[apiGroup][kind] + } - const domain = storeGet('/domain') || '' - if (domain.includes('bb.test')) { - return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` - } else { - const editedDomain = domain.replace('kubedb', 'console') - return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + function returnFalse() { + return false } -} -function getApiGroup() { - return ['core', 'apps', 'kubedb.com'] -} + function onStorageRefNamespaceChange() { + // Clear the name when namespace changes + commit('wizard/model$update', { + path: '/spec/storageRef/name', + value: '', + force: true, + }) + } -async function getTargetName({ watchDependency, getValue, model, axios, storeGet }) { - watchDependency('model#/spec/appRef/apiGroup') - watchDependency('model#/spec/appRef/namespace') - watchDependency('model#/spec/appRef/kind') - const apiGroup = getValue(model, `/spec/appRef/apiGroup`) - const namespace = getValue(model, `/spec/appRef/namespace`) - const resource = getResourceName({ getValue, model }) - const params = storeGet('/route/params') - const { user, cluster } = params - - const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` - if (apiGroup && version && resource && namespace) { - try { - const resp = await axios.get(url) - const items = resp.data?.items - const options = items.map((ele) => { - return ele.metadata.name - }) - return options - } catch (e) { - console.log(e) - } + function onEncryptionSecretNamespaceChange() { + // Clear the name when namespace changes + commit('wizard/model$update', { + path: '/spec/encryptionSecret/name', + value: '', + force: true, + }) } - return [] -} -function getResourceName({ getValue, model }) { - const apiGroup = getValue(model, `/spec/appRef/apiGroup`) - const kind = getValue(model, `/spec/appRef/kind`) - if (!kind || !apiGroup) return '' - return kindToResourceMap[apiGroup][kind] -} + function onApiGroupChange() { + // Clear kind, namespace, and name when apiGroup changes + commit('wizard/model$update', { + path: '/spec/appRef/kind', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/appRef/namespace', + value: '', + force: true, + }) + commit('wizard/model$update', { + path: '/spec/appRef/name', + value: '', + force: true, + }) + } -function returnFalse() { - return false -} + function onAppRefNamespaceChange() { + // Clear the name when namespace changes + commit('wizard/model$update', { + path: '/spec/appRef/name', + value: '', + force: true, + }) + } -return { - getKindsApi, - getNamespacesApi, - init, - getCreateNameSpaceUrl, - isRancherManaged, - fetchNamespaces, - fetchNames, - getApiGroup, - getTargetName, - getKinds, - getResourceName, - returnFalse, - setVersion, + return { + getKindsApi, + getNamespacesApi, + init, + getCreateNameSpaceUrl, + isRancherManaged, + fetchNamespaces, + fetchNames, + getApiGroup, + getTargetName, + getKinds, + getResourceName, + returnFalse, + setVersion, + onStorageRefNamespaceChange, + onEncryptionSecretNamespaceChange, + onApiGroupChange, + onAppRefNamespaceChange, + } } diff --git a/charts/storagekubestashcom-repository-editor-options/ui/old.create-ui.yaml b/charts/storagekubestashcom-repository-editor-options/ui/old.create-ui.yaml new file mode 100644 index 0000000000..4dbb2a9289 --- /dev/null +++ b/charts/storagekubestashcom-repository-editor-options/ui/old.create-ui.yaml @@ -0,0 +1,169 @@ +steps: +- form: + discriminator: + nameSpaceApi: + default: false + type: boolean + elements: + - computed: init + if: returnFalse + type: input + - elements: + - fetch: getNamespacesApi + hasGroup: isRancherManaged + label: + text: labels.namespace + schema: + $ref: schema#/properties/metadata/properties/release/properties/namespace + type: select + - label: + text: labels.repository.name + schema: + $ref: schema#/properties/metadata/properties/release/properties/name + type: input + schema: + $ref: schema#/properties/metadata/properties/release + type: single-step-form + - discriminator: + existingAuthSecrets: + default: [] + type: Array + isExistingAuthSecretsFetching: + default: true + type: boolean + useExistingAuthSecret: + default: true + type: boolean + elements: + - isArray: true + keys: + label: + text: labels.key + label: + text: labels.repository.labels + schema: + $ref: schema#/properties/spec/properties/labels + type: key-value-input-form + values: + label: + text: labels.value + schema: + $ref: schema#/properties/spec/properties/labels/additionalProperties + type: input + - isArray: true + keys: + label: + text: labels.key + label: + text: labels.repository.annotations + schema: + $ref: schema#/properties/spec/properties/annotations + type: key-value-input-form + values: + label: + text: labels.value + schema: + $ref: schema#/properties/spec/properties/annotations/additionalProperties + type: input + - label: + text: Deletion Policy + options: + - Delete + - WipeOut + schema: + $ref: schema#/properties/spec/properties/deletionPolicy + type: select + - elements: + - disableUnselect: true + fetch: fetchNamespaces + hasGroup: isRancherManaged + label: + text: labels.namespace + refresh: true + schema: + $ref: schema#/properties/spec/properties/storageRef/properties/namespace + type: select + - disableUnselect: true + fetch: fetchNames|storageRef + label: + text: labels.name + refresh: true + schema: + $ref: schema#/properties/spec/properties/storageRef/properties/name + type: select + label: + text: labels.storageRef + schema: + $ref: schema#/properties/spec/properties/storageRef + show_label: true + type: single-step-form + - elements: + - disableUnselect: true + fetch: fetchNamespaces + hasGroup: isRancherManaged + label: + text: labels.namespace + refresh: true + schema: + $ref: schema#/properties/spec/properties/encryptionSecret/properties/namespace + type: select + - disableUnselect: true + fetch: fetchNames|encryptionSecret + label: + text: labels.name + refresh: true + schema: + $ref: schema#/properties/spec/properties/encryptionSecret/properties/name + type: select + label: + text: labels.encryptionSecret + schema: + $ref: schema#/properties/spec/properties/encryptionSecret + show_label: true + type: single-step-form + - label: + text: Path + schema: + $ref: schema#/properties/spec/properties/path + type: input + - elements: + - fetch: getApiGroup + label: + text: Api Group + schema: + $ref: schema#/properties/spec/properties/appRef/properties/apiGroup + type: select + - fetch: getKinds + label: + text: Kind + onChange: setVersion + schema: + $ref: schema#/properties/spec/properties/appRef/properties/kind + sortable: true + type: select + - fetch: fetchNamespaces + hasGroup: isRancherManaged + label: + text: Namespace + schema: + $ref: schema#/properties/spec/properties/appRef/properties/namespace + type: select + - fetch: getTargetName + label: + text: Name + schema: + $ref: schema#/properties/spec/properties/appRef/properties/name + type: select + label: + text: App Ref + schema: + $ref: schema#/properties/spec/properties/appRef + show_label: true + type: single-step-form + schema: + $ref: schema#/properties/spec + type: single-step-form + type: single-step-form + id: options + title: steps.0.label +type: multi-step-form diff --git a/charts/storagekubestashcom-repository-editor-options/ui/old.functions.js b/charts/storagekubestashcom-repository-editor-options/ui/old.functions.js new file mode 100644 index 0000000000..01c87284b4 --- /dev/null +++ b/charts/storagekubestashcom-repository-editor-options/ui/old.functions.js @@ -0,0 +1,242 @@ +let namespaces = [] +let appKind = [] +let coreKind = [] +let kubedbKind = [] +let availableKinds = {} +let kindToResourceMap = {} +let version = '' + +function init({ watchDependency, model, getValue, storeGet, axios, setDiscriminatorValue }) { + namespaces = getNamespacesApi({ axios, storeGet }) + getKindsApi({ watchDependency, model, getValue, storeGet, axios }) + setDiscriminatorValue('/nameSpaceApi', true) +} + +function getKinds({ watchDependency, getValue, model }) { + watchDependency(`model#/spec/appRef/apiGroup`) + const apiGroup = getValue(model, `/spec/appRef/apiGroup`) + console.log(apiGroup) + + if (apiGroup === 'core') return coreKind + else if (apiGroup === 'apps') return appKind + else return kubedbKind +} + +function setVersion({ getValue, model }) { + let apiGroup = getValue(model, `/spec/appRef/apiGroup`) + const kind = getValue(model, `/spec/appRef/kind`) + if (apiGroup === 'core') apiGroup = '' + console.log(availableKinds) + + Object.keys(availableKinds[apiGroup]).forEach((vs) => { + availableKinds[apiGroup][vs].forEach((ele) => { + if (ele.Kind === kind) { + version = vs + } + }) + }) +} + +async function getKindsApi({ storeGet, axios }) { + const params = storeGet('/route/params') + const { user, cluster } = params + let url = `/clusters/${user}/${cluster}/available-types?groups=core,apps,kubedb.com` + try { + const resp = await axios.get(url) + + kindToResourceMap['kubedb.com'] = {} + kindToResourceMap['apps'] = {} + kindToResourceMap['core'] = {} + + availableKinds = resp.data + appKind = Object.values(availableKinds['apps']) + .flat() + .map((ele) => { + kindToResourceMap['apps'][ele.Kind] = ele.Resource + return ele.Kind + }) + kubedbKind = Object.values(availableKinds['kubedb.com']) + .flat() + .map((ele) => { + kindToResourceMap['kubedb.com'][ele.Kind] = ele.Resource + return ele.Kind + }) + coreKind = Object.values(availableKinds['']) + .flat() + .map((ele) => { + kindToResourceMap['core'][ele.Kind] = ele.Resource + return ele.Kind + }) + } catch (e) { + console.log(e) + } + return [] +} + +function isRancherManaged({ storeGet }) { + const managers = storeGet('/cluster/clusterDefinition/result/clusterManagers') + const found = managers.find((item) => item === 'Rancher') + return !!found +} + +function fetchNamespaces({ watchDependency }) { + watchDependency('discriminator#/nameSpaceApi') + return namespaces +} +async function getNamespacesApi({ axios, storeGet }) { + const params = storeGet('/route/params') + const { user, cluster, group, version, resource } = params + try { + const resp = await axios.post( + `/clusters/${user}/${cluster}/proxy/identity.k8s.appscode.com/v1alpha1/selfsubjectnamespaceaccessreviews`, + { + apiVersion: 'identity.k8s.appscode.com/v1alpha1', + kind: 'SelfSubjectNamespaceAccessReview', + spec: { + resourceAttributes: [ + { + verb: 'create', + group: group, + version: version, + resource: resource, + }, + ], + }, + }, + ) + if (resp.data?.status?.projects) { + const projects = resp.data?.status?.projects + let projectsNamespace = [] + projectsNamespace = Object.keys(projects).map((project) => ({ + project: project, + namespaces: projects[project].map((namespace) => ({ + text: namespace, + value: namespace, + })), + })) + return projectsNamespace + } else { + return resp.data?.status?.namespaces || [] + } + } catch (e) { + console.log(e) + } + return [] +} + +async function fetchNames({ getValue, model, storeGet, watchDependency, axios }, type) { + watchDependency(`model#/spec/${type}/namespace`) || '' + const user = storeGet('/route/params/user') || '' + const cluster = storeGet('/route/params/cluster') || '' + const namespace = getValue(model, `/spec/${type}/namespace`) || '' + let suffix = type + if (type === 'encryptionSecret') suffix = 'secrets' + else if (type === 'repository') suffix = 'repositories' + else if (type === 'storageRef') suffix = 'backupstorages' + const core = suffix === 'secrets' ? 'core' : 'storage.kubestash.com' + const version = suffix === 'secrets' ? 'v1' : 'v1alpha1' + const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/${suffix}` + + try { + if (namespace) { + const resp = await axios.get(url) + let names = resp?.data?.items + names.map((item) => { + item.value = item?.metadata?.name || '' + item.text = item?.metadata?.name || '' + return true + }) + + if (type === 'repository') { + const resource = storeGet('/resource/layout/result/resource') || {} + let group = resource?.group || '' + let kind = resource?.kind || '' + + if (isConsole({ storeGet })) { + group = getValue(model, '/spec/appRef/apiGroup') || '' + kind = getValue(model, '/spec/appRef/kind') || '' + } + + const filteredRepo = names.filter((item) => { + const appRef = item?.spec?.appRef || {} + return appRef?.apiGroup === group && appRef?.kind === kind + }) + return filteredRepo + } + return names + } + } catch (e) { + console.log(e) + } + return [] +} + +function getCreateNameSpaceUrl({ model, getValue, storeGet }) { + const user = storeGet('/route/params/user') + const cluster = storeGet('/route/params/cluster') + + const domain = storeGet('/domain') || '' + if (domain.includes('bb.test')) { + return `http://console.bb.test:5990/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } else { + const editedDomain = domain.replace('kubedb', 'console') + return `${editedDomain}/${user}/kubernetes/${cluster}/core/v1/namespaces/create` + } +} + +function getApiGroup() { + return ['core', 'apps', 'kubedb.com'] +} + +async function getTargetName({ watchDependency, getValue, model, axios, storeGet }) { + watchDependency('model#/spec/appRef/apiGroup') + watchDependency('model#/spec/appRef/namespace') + watchDependency('model#/spec/appRef/kind') + const apiGroup = getValue(model, `/spec/appRef/apiGroup`) + const namespace = getValue(model, `/spec/appRef/namespace`) + const resource = getResourceName({ getValue, model }) + const params = storeGet('/route/params') + const { user, cluster } = params + + const url = `/clusters/${user}/${cluster}/proxy/${apiGroup}/${version}/namespaces/${namespace}/${resource}` + if (apiGroup && version && resource && namespace) { + try { + const resp = await axios.get(url) + const items = resp.data?.items + const options = items.map((ele) => { + return ele.metadata.name + }) + return options + } catch (e) { + console.log(e) + } + } + return [] +} + +function getResourceName({ getValue, model }) { + const apiGroup = getValue(model, `/spec/appRef/apiGroup`) + const kind = getValue(model, `/spec/appRef/kind`) + if (!kind || !apiGroup) return '' + return kindToResourceMap[apiGroup][kind] +} + +function returnFalse() { + return false +} + +return { + getKindsApi, + getNamespacesApi, + init, + getCreateNameSpaceUrl, + isRancherManaged, + fetchNamespaces, + fetchNames, + getApiGroup, + getTargetName, + getKinds, + getResourceName, + returnFalse, + setVersion, +} diff --git a/schemas/ui-schema.json b/schemas/ui-schema.json index 04472dee3d..74f960acf1 100644 --- a/schemas/ui-schema.json +++ b/schemas/ui-schema.json @@ -1,4745 +1,1364 @@ { - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/UiInterface", - "definitions": { - "UiInterface": { - "anyOf": [ - { - "$ref": "#/definitions/MultiStepFormInterface" - }, - { - "$ref": "#/definitions/SingleStepFormInterface" - }, - { - "$ref": "#/definitions/FormElementType" - } - ] + "$ref": "#/definitions/FormType", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "AllElement": { + "anyOf": [ + { + "$ref": "#/definitions/BaseElement" }, - "MultiStepFormInterface": { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "multi-step-form" - }, - "steps": { - "type": "array", - "items": { - "type": "object", - "properties": { - "title": { - "type": "string" - }, - "id": { - "type": "string" - }, - "if": { - "type": "string" - }, - "form": { - "anyOf": [ - { - "$ref": "#/definitions/MultiStepFormInterface" - }, - { - "$ref": "#/definitions/SingleStepFormInterface" - } - ] - } - }, - "required": [ - "title", - "id", - "form" - ], - "additionalProperties": false - } - } - }, - "required": [ - "type", - "steps" - ], - "additionalProperties": false - }, - "SingleStepFormInterface": { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "single-step-form" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "identifier": { - "type": "string" - }, - "show_label": { - "type": "boolean" - }, - "hideForm": { - "type": "boolean" - }, - "accordion": { - "type": "boolean" - }, - "elements": { - "type": "array", - "items": { - "$ref": "#/definitions/FormElementType" - } - }, - "discriminator": { - "type": "object", - "additionalProperties": {} - }, - "style": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "toggleOption": { - "$ref": "#/definitions/ToggleOption" - } - }, - "required": [ - "elements", - "type" - ], - "additionalProperties": false - }, - "FormElementType": { - "anyOf": [ - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "label-element" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "alertInfo": { - "type": "object", - "properties": { - "show": { - "type": "boolean" - }, - "type": { - "type": "string", - "enum": [ - "success", - "info", - "error", - "neutral" - ] - }, - "hideIcon": { - "type": "boolean" - }, - "actionButton": { - "type": "object", - "properties": { - "show": { - "type": "boolean" - }, - "title": { - "type": "string" - }, - "iconClass": { - "type": "string" - }, - "action": {} - }, - "required": [ - "show", - "title", - "iconClass", - "action" - ], - "additionalProperties": false - } - }, - "required": [ - "type" - ], - "additionalProperties": false - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "tabs" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "tabs": { - "type": "array", - "items": { - "type": "object", - "properties": { - "value": { - "type": [ - "string", - "number", - "boolean" - ] - }, - "title": { - "type": "string" - } - }, - "required": [ - "value", - "title" - ], - "additionalProperties": false - } - } - }, - "required": [ - "tabs", - "type" - ], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "anchor" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "target": { - "type": "string" - }, - "url": { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - }, - "required": [ - "type", - "url" - ], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "input" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "hideValue": { - "type": "boolean" - }, - "inputType": { - "type": "string" - }, - "showPasswordStrength": { - "type": "boolean" - }, - "minValue": { - "type": "number" - }, - "maxValue": { - "type": "number" - }, - "validationRuleObject": { - "type": "object", - "additionalProperties": {} - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "$ref": "#/definitions/TimeInputInterface" - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "textarea" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - } - }, - "required": [ - "type" - ], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "editor" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "language": { - "type": "string", - "enum": [ - "json", - "yaml" - ] - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "select" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "add_new_button": { - "type": "object", - "properties": { - "url": { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - }, - "target": { - "type": "string" - }, - "label": { - "type": "string" - } - }, - "required": [ - "url" - ], - "additionalProperties": false - }, - "allowUserDefinedOption": { - "type": "boolean" - }, - "options": { - "type": "array", - "items": { - "anyOf": [ - { - "type": "string" - }, - { - "$ref": "#/definitions/Option" - }, - { - "$ref": "#/definitions/Project" - } - ] - } - }, - "refresh": { - "type": "boolean" - }, - "sortable": { - "type": "boolean" - }, - "disableUnselect": { - "type": "boolean" - }, - "hasGroup": { - "type": [ - "boolean", - "string" - ] - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "multiselect" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "add_new_button": { - "type": "object", - "properties": { - "url": { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - }, - "target": { - "type": "string" - }, - "label": { - "type": "string" - } - }, - "required": [ - "url" - ], - "additionalProperties": false - }, - "allowUserDefinedOption": { - "type": "boolean" - }, - "options": { - "type": "array", - "items": { - "anyOf": [ - { - "type": "string" - }, - { - "$ref": "#/definitions/Option" - }, - { - "$ref": "#/definitions/Project" - } - ] - } - }, - "refresh": { - "type": "boolean" - }, - "sortable": { - "type": "boolean" - }, - "disableUnselect": { - "type": "boolean" - }, - "hasGroup": { - "type": [ - "boolean", - "string" - ] - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "checkbox" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "options": { - "type": "array", - "items": { - "$ref": "#/definitions/Option" - } - }, - "hasDescription": { - "type": "boolean" - }, - "isHorizontal": { - "type": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "radio" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "options": { - "type": "array", - "items": { - "$ref": "#/definitions/Option" - } - }, - "hasDescription": { - "type": "boolean" - }, - "isHorizontal": { - "type": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "switch" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - } - }, - "required": [ - "type" - ], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "key-value-input-form" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "isArray": { - "type": "boolean" - }, - "newItemValidator": { - "type": "string" - }, - "keys": { - "type": "object", - "properties": { - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "required": [ - "label" - ], - "additionalProperties": false - }, - "values": { - "$ref": "#/definitions/FormElementType" - } - }, - "required": [ - "keys", - "type", - "values" - ], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "key-text-area-input-form" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "isArray": { - "type": "boolean" - }, - "newItemValidator": { - "type": "string" - }, - "keys": { - "type": "object", - "properties": { - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "required": [ - "label" - ], - "additionalProperties": false - }, - "values": { - "$ref": "#/definitions/FormElementType" - } - }, - "required": [ - "keys", - "type", - "values" - ], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "list-input-form" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "element": { - "$ref": "#/definitions/FormElementType" - }, - "validationRuleObject": { - "type": "object", - "additionalProperties": {} - } - }, - "required": [ - "element", - "type" - ], - "additionalProperties": false - }, - { - "$ref": "#/definitions/SingleStepFormArrayInterface" - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "reusable-element" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "identifier": { - "type": "string" - }, - "show_label": { - "type": "boolean" - }, - "hideForm": { - "type": "boolean" - }, - "accordion": { - "type": "boolean" - }, - "elements": { - "type": "array", - "items": { - "$ref": "#/definitions/FormElementType" - } - }, - "discriminator": { - "type": "object", - "additionalProperties": {} - }, - "style": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "toggleOption": { - "$ref": "#/definitions/ToggleOption" - }, - "alias": { - "type": "string" - }, - "chart": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "version": { - "type": "string" - } - }, - "required": [ - "name", - "version" - ], - "additionalProperties": false - }, - "moduleResolver": { - "type": "string" - }, - "dataContext": { - "type": "object", - "additionalProperties": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - }, - "functionCallbacks": { - "type": "object", - "additionalProperties": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - } - }, - "required": [ - "alias", - "chart", - "moduleResolver", - "type" - ], - "additionalProperties": false - }, - { - "$ref": "#/definitions/SingleStepFormInterface" - }, - { - "$ref": "#/definitions/ConfigureOptionsInterface" - }, - { - "$ref": "#/definitions/ArrayInputFormElementInterface" - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "resource-input-form" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - } - }, - "required": [ - "type" - ], - "additionalProperties": false - } - ] + { + "$ref": "#/definitions/DerivedElement" }, - "TimeInputInterface": { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "time-input" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - } - }, - "required": [ - "type" - ], - "additionalProperties": false + { + "$ref": "#/definitions/LayoutElement" + } + ] + }, + "Anchor": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" }, - "Option": { - "type": "object", - "properties": { - "text": { - "type": "string" - }, - "value": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "boolean" - }, - { - "type": "object", - "additionalProperties": {} - }, - { - "type": "array", - "items": {} - } - ] - }, - "description": { - "type": "string" - } - }, - "required": [ - "text", - "value" - ], - "additionalProperties": false - }, - "Project": { - "type": "object", - "properties": { - "project": { - "type": "string" - }, - "namespaces": { - "type": "array", - "items": { - "$ref": "#/definitions/Namespace" - } - } - }, - "required": [ - "project", - "namespaces" - ], - "additionalProperties": false - }, - "Namespace": { - "type": "object", - "properties": { - "text": { - "type": "string" - }, - "value": { - "type": "string" - } + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "anchor", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "ArrayItem": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "element": { + "$ref": "#/definitions/BaseElement" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "array-item-form", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["element", "label", "schema", "type"], + "type": "object" + }, + "ArrayObject": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "elements": { + "items": { + "$ref": "#/definitions/BaseElement" + }, + "type": "array" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "array-object-form", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["elements", "label", "schema", "type"], + "type": "object" + }, + "BaseElement": { + "anyOf": [ + { + "$ref": "#/definitions/Label" + }, + { + "$ref": "#/definitions/Input" + }, + { + "$ref": "#/definitions/Select" + }, + { + "$ref": "#/definitions/TheSelect" + }, + { + "$ref": "#/definitions/TextArea" + }, + { + "$ref": "#/definitions/Radio" + }, + { + "$ref": "#/definitions/CheckBox" + }, + { + "$ref": "#/definitions/Switch" + }, + { + "$ref": "#/definitions/Anchor" + }, + { + "$ref": "#/definitions/EditorView" + }, + { + "$ref": "#/definitions/TimePicker" + }, + { + "$ref": "#/definitions/ThresholdInput" + }, + { + "$ref": "#/definitions/InputCompare" + } + ] + }, + "BlockLayout": { + "additionalProperties": false, + "properties": { + "description": { + "type": "string" + }, + "elements": { + "items": { + "$ref": "#/definitions/AllElement" + }, + "type": "array" + }, + "hideBlock": { + "type": "boolean" + }, + "hideBorder": { + "type": "boolean" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "type": "string" + }, + "showLabels": { + "type": "boolean" + }, + "type": { + "const": "block-layout", + "type": "string" + } + }, + "required": ["elements", "type"], + "type": "object" + }, + "CheckBox": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "options": { + "$ref": "#/definitions/Options" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "checkbox", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "DerivedElement": { + "anyOf": [ + { + "$ref": "#/definitions/ArrayObject" + }, + { + "$ref": "#/definitions/ArrayItem" + }, + { + "$ref": "#/definitions/ObjectItem" + }, + { + "$ref": "#/definitions/ScalingRules" + }, + { + "$ref": "#/definitions/MachineElement" + }, + { + "$ref": "#/definitions/SelectElement" + } + ] + }, + "EditorView": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "data": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "editorHeight": { + "type": "string" + }, + "hasCopy": { + "type": "boolean" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "readonly": { + "type": "boolean" + }, + "schema": { + "type": "string" + }, + "showCodeGroup": { + "type": "boolean" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "editor", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["hasCopy", "label", "schema", "type"], + "type": "object" + }, + "FormType": { + "anyOf": [ + { + "$ref": "#/definitions/SingleStepForm" + }, + { + "$ref": "#/definitions/MultiStepForm" + } + ] + }, + "HorizontalLayout": { + "additionalProperties": false, + "properties": { + "description": { + "type": "string" + }, + "elements": { + "items": { + "$ref": "#/definitions/AllElement" + }, + "type": "array" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "type": "string" + }, + "showLabels": { + "type": "boolean" + }, + "type": { + "const": "horizontal-layout", + "type": "string" + } + }, + "required": ["elements", "type"], + "type": "object" + }, + "IfType": { + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "type": { + "enum": ["function", "computed"], + "type": "string" + } + }, + "required": ["type", "name"], + "type": "object" + }, + "Init": { + "anyOf": [ + { + "additionalProperties": false, + "properties": { + "type": { + "const": "func", + "type": "string" }, - "required": [ - "text", - "value" - ], - "additionalProperties": false - }, - "SingleStepFormArrayInterface": { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "single-step-form-array" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "addFormLabel": { - "type": "string" - }, - "hideForm": { - "type": "boolean" - }, - "isCreateDisabled": { - "type": "boolean" - }, - "element": { - "$ref": "#/definitions/SingleStepFormInterface" - }, - "newItemValidator": { - "type": "string" - }, - "tableContents": { - "type": "array", - "items": { - "$ref": "#/definitions/TableContent" - } - }, - "temporaryPath": { - "type": "string" - }, - "resetOnChange": { - "type": "boolean" - }, - "resetDependencyPath": { - "type": "string" - }, - "hideDetailsButton": { - "type": "boolean" - }, - "validationRuleObject": { - "type": "object", - "additionalProperties": {} - } + "value": { + "type": "string" + } + }, + "required": ["type", "value"], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "type": { + "const": "static", + "type": "string" }, - "required": [ - "element", - "tableContents", - "type" - ], - "additionalProperties": false - }, - "TableContent": { - "anyOf": [ - { - "$ref": "#/definitions/TableContentValueInterface" - }, - { - "type": "object", - "properties": { - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "type": { - "type": "string", - "const": "label" - } - }, - "required": [ - "label", - "type" - ], - "additionalProperties": false - } - ] + "value": {} + }, + "required": ["type", "value"], + "type": "object" + } + ] + }, + "Input": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "isSecret": { + "type": "boolean" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "enum": ["input", "date", "date-time"], + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "InputCompare": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "header": { + "type": "string" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "input-compare", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "Label": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" }, - "TableContentValueInterface": { - "type": "object", - "properties": { - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "type": { - "type": "string", - "const": "value" - }, - "computed": { - "type": "string" - }, - "inTableColumn": { - "type": "boolean" - }, - "path": { - "type": "string" - }, - "typeOfValue": { - "type": "string", - "enum": [ - "string", - "array", - "object-array", - "key-operator-values-array", - "key-value", - "code", - "datetime" - ] - }, - "tableContents": { - "type": "array", - "items": { - "$ref": "#/definitions/TableContent" - } - } + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "enum": ["label-element", "alert", "info", "warning", "error", "success"], + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "type"], + "type": "object" + }, + "LayoutElement": { + "anyOf": [ + { + "$ref": "#/definitions/BlockLayout" + }, + { + "$ref": "#/definitions/HorizontalLayout" + } + ] + }, + "LoaderType": { + "anyOf": [ + { + "type": "string" + }, + { + "additionalProperties": false, + "properties": { + "name": { + "type": "string" }, - "required": [ - "label", - "path", - "type", - "typeOfValue" - ], - "additionalProperties": false - }, - "ToggleOption": { - "type": "object", + "watchPaths": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": ["name"], + "type": "object" + } + ] + }, + "MachineElement": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "header": { + "type": "string" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "machine-compare", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "MultiStepForm": { + "additionalProperties": false, + "properties": { + "label": { + "type": "string" + }, + "loader": { + "type": "string" + }, + "step": { + "items": { + "$ref": "#/definitions/SingleStepForm" + }, + "type": "array" + }, + "type": { + "const": "multi-step-form", + "type": "string" + } + }, + "required": ["type", "step"], + "type": "object" + }, + "ObjectItem": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "object-item", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "Options": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "items": { + "additionalProperties": false, "properties": { - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "id": { - "type": "string" - }, - "onStatusFalse": { - "type": "string" - }, - "onStatusTrue": { - "type": "string" - }, - "setInitialStatusFalse": { - "type": [ - "boolean", - "string" - ] - }, - "show": { - "type": "boolean" - }, - "ignoreInitialStatusFunction": { - "type": "boolean" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } + "description": { + "type": "string" + }, + "label": { + "type": "string" + }, + "text": { + "type": "string" + }, + "value": { + "type": "string" + } }, - "required": [ - "id" - ], - "additionalProperties": false + "required": ["text", "value"], + "type": "object" + }, + "type": "array" }, - "ConfigureOptionsInterface": { - "type": "object", + { + "items": { + "additionalProperties": false, "properties": { - "type": { - "type": "string", - "const": "configure-options" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } + "namespaces": { + "items": { + "additionalProperties": false, + "properties": { + "text": { + "type": "string" }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "options": { - "type": "array", - "items": { - "$ref": "#/definitions/ConfigureOption" - } - }, - "hasDescription": { - "type": "boolean" - }, - "isHorizontal": { - "type": "boolean" - }, - "hasDependencies": { - "type": "boolean" - }, - "owner": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - }, - "cluster": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "required": [ - "cluster", - "options", - "owner", - "type" - ], - "additionalProperties": false - }, - "ConfigureOption": { - "type": "object", - "properties": { - "text": { - "type": "string" - }, - "value": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "boolean" - }, - { - "type": "object", - "additionalProperties": {} - }, - { - "type": "array", - "items": {} - } - ] - }, - "description": { - "type": "string" - }, - "dependencies": { - "type": "array", - "items": { - "type": "object", - "properties": { - "group": { - "type": "string" - }, - "version": { - "type": "string" - }, - "name": { - "type": "string" - }, - "resource": { - "type": "string" - }, - "url": { - "type": "string" - } - }, - "required": [ - "group", - "version", - "name", - "resource", - "url" - ], - "additionalProperties": false - } - }, - "dependingSteps": { - "type": "array", - "items": { - "type": "string" + "value": { + "type": "string" } - } + }, + "required": ["text", "value"], + "type": "object" + }, + "type": "array" + }, + "project": { + "type": "string" + } }, - "additionalProperties": false, - "required": [ - "text", - "value" - ] + "required": ["project", "namespaces"], + "type": "object" + }, + "type": "array" + } + ] + }, + "Radio": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" }, - "ArrayInputFormElementInterface": { - "type": "object", - "properties": { - "type": { - "type": "string", - "const": "array-input-form" - }, - "label": { - "type": "object", - "properties": { - "isSubsection": { - "type": "boolean" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false - }, - "customClass": { - "type": "string" - }, - "schema": { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - }, - "disabled": { - "type": [ - "boolean", - "string" - ] - }, - "required": { - "type": [ - "boolean", - "string" - ] - }, - "if": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - }, - "expression": { - "type": "string" - } - }, - "required": [ - "params", - "expression" - ], - "additionalProperties": false - } - ] - }, - "fetch": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "function": { - "type": "string" - }, - "params": { - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "number" - }, - { - "type": "object", - "properties": { - "$ref": { - "type": "string" - } - }, - "required": [ - "$ref" - ], - "additionalProperties": false - } - ] - } - } - }, - "additionalProperties": false - } - ] - }, - "computed": { - "type": "string" - }, - "individualItemDisabilityCheck": { - "type": "string" - }, - "onChange": { - "type": "string" - }, - "encoder": { - "type": "string" - }, - "decoder": { - "type": "string" - }, - "keepEmpty": { - "type": "boolean" - }, - "description": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "text": { - "type": "string" - } - }, - "required": [ - "text" - ], - "additionalProperties": false - } - ] - }, - "identifier": { - "type": "string" - }, - "element": { - "$ref": "#/definitions/FormElementType" - }, - "show_label": { - "type": "boolean" - }, - "hideForm": { - "type": "boolean" + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "isHorizontal": { + "type": "boolean" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "options": { + "$ref": "#/definitions/Options" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "radio", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "ScalingRules": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "scaling-rules", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "Select": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "disableUnselect": { + "type": "boolean" + }, + "hasGroup": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "options": { + "$ref": "#/definitions/Options" + }, + "refresh": { + "type": "boolean" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "select", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "SelectElement": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "header": { + "type": "string" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "select-compare", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "SingleStepForm": { + "additionalProperties": false, + "properties": { + "elements": { + "items": { + "$ref": "#/definitions/AllElement" + }, + "type": "array" + }, + "id": { + "type": "string" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "single-step-form", + "type": "string" + } + }, + "required": ["type", "elements"], + "type": "object" + }, + "Switch": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "fullwidth": { + "type": "boolean" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "switch", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "TextArea": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "height": { + "type": "string" + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "textarea", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "TheSelect": { + "additionalProperties": false, + "properties": { + "addNewButton": { + "additionalProperties": false, + "properties": { + "label": { + "type": "string" + }, + "target": { + "type": "string" + }, + "url": { + "anyOf": [ + { + "type": "string" }, - "style": { - "type": "object", - "additionalProperties": { - "type": "string" + { + "additionalProperties": false, + "properties": { + "function": { + "type": "string" } - }, - "individualItemVisibilityCheck": { - "type": "string" + }, + "required": ["function"], + "type": "object" } + ] + } + }, + "required": ["label", "url"], + "type": "object" + }, + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "disableUnselect": { + "type": "boolean" + }, + "hasGroup": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "multiple": { + "type": "boolean" + }, + "options": { + "$ref": "#/definitions/Options" + }, + "refresh": { + "type": "boolean" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "select", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "ThresholdInput": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "maxValue": { + "type": "number" + }, + "minValue": { + "type": "number" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "threshold-input", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + }, + "width": { + "type": "string" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "TimePicker": { + "additionalProperties": false, + "properties": { + "customClass": { + "type": "string" + }, + "description": { + "type": "string" + }, + "disable": { + "type": ["boolean", "string"] + }, + "if": { + "$ref": "#/definitions/IfType" + }, + "init": { + "$ref": "#/definitions/Init" + }, + "label": { + "type": "string" + }, + "loader": { + "$ref": "#/definitions/LoaderType" + }, + "schema": { + "type": "string" + }, + "subtitle": { + "type": "string" + }, + "type": { + "const": "time-picker", + "type": "string" + }, + "validation": { + "$ref": "#/definitions/Validation" + }, + "watcher": { + "$ref": "#/definitions/Watchers" + } + }, + "required": ["label", "schema", "type"], + "type": "object" + }, + "Validation": { + "anyOf": [ + { + "additionalProperties": false, + "properties": { + "type": { + "const": "required", + "type": "string" + } + }, + "required": ["type"], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "name": { + "type": "string" }, - "required": [ - "element", - "type" - ], - "additionalProperties": false + "type": { + "const": "custom", + "type": "string" + } + }, + "required": ["type", "name"], + "type": "object" + } + ] + }, + "Watchers": { + "additionalProperties": false, + "properties": { + "func": { + "type": "string" + }, + "paths": { + "items": { + "type": "string" + }, + "type": "array" } + }, + "required": ["paths", "func"], + "type": "object" } + } } \ No newline at end of file