Skip to content

Commit 2660d35

Browse files
committed
fix machine resource in scaling ops for mongos
Signed-off-by: shofiq <shofiq@appscode.com>
1 parent 55f1d1c commit 2660d35

2 files changed

Lines changed: 38 additions & 47 deletions

File tree

charts/opskubedbcom-mongodbopsrequest-editor/ui/create-ui.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ step:
238238
name: isMachineValid|standalone
239239
type: custom
240240
watcher:
241-
func: onMachineChange|standalone|/spec/podTemplate/spec/resources
241+
func: onMachineChange|standalone
242242
paths:
243243
- temp/properties/machine-standalone
244244
- elements:
@@ -307,7 +307,7 @@ step:
307307
name: isMachineValid|replicaSet
308308
type: custom
309309
watcher:
310-
func: onMachineChange|replicaSet|/spec/podTemplate/spec/resources
310+
func: onMachineChange|replicaSet
311311
paths:
312312
- temp/properties/machine-replicaSet
313313
- elements:
@@ -376,8 +376,11 @@ step:
376376
subtitle: Compare your current machine configuration with the proposed memory
377377
adjustments and make informed decisions for your database setup
378378
type: machine-compare
379+
validation:
380+
name: isMachineValid|configServer
381+
type: custom
379382
watcher:
380-
func: onMachineChange|configServer|/spec/shardTopology/configServer/podTemplate/spec/resources
383+
func: onMachineChange|configServer
381384
paths:
382385
- temp/properties/machine-configServer
383386
- elements:
@@ -441,8 +444,11 @@ step:
441444
subtitle: Compare your current machine configuration with the proposed memory
442445
adjustments and make informed decisions for your database setup
443446
type: machine-compare
447+
validation:
448+
name: isMachineValid|mongos
449+
type: custom
444450
watcher:
445-
func: onMachineChange|mongos|/spec/shardTopology/mongos/podTemplate/spec/resources
451+
func: onMachineChange|mongos
446452
paths:
447453
- temp/properties/machine-mongos
448454
- elements:
@@ -506,8 +512,11 @@ step:
506512
subtitle: Compare your current machine configuration with the proposed memory
507513
adjustments and make informed decisions for your database setup
508514
type: machine-compare
515+
validation:
516+
name: isMachineValid|shard
517+
type: custom
509518
watcher:
510-
func: onMachineChange|shard|/spec/shardTopology/shard/podTemplate/spec/resources
519+
func: onMachineChange|shard
511520
paths:
512521
- temp/properties/machine-shard
513522
- elements:
@@ -581,10 +590,6 @@ step:
581590
label: Memory
582591
schema: schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/properties/memory
583592
type: input
584-
watcher:
585-
func: onExporterResourceChange|memory
586-
paths:
587-
- schema/properties/spec/properties/verticalScaling/properties/exporter/properties/resources/properties/limits/properties/memory
588593
showLabels: true
589594
type: horizontal-layout
590595
hideBlock: true

charts/opskubedbcom-mongodbopsrequest-editor/ui/functions.js

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,10 @@ export const useFunc = (model) => {
432432
const cluster = storeGet('/route/params/cluster')
433433
const namespace = storeGet('/route/query/namespace') || getValue(model, '/metadata/namespace')
434434
const name = storeGet('/route/params/name') || getValue(model, '/spec/databaseRef/name')
435+
const version = storeGet('/route/params/version')
435436

436437
if (namespace && name) {
437-
const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/v1alpha2/namespaces/${namespace}/mongodbs/${name}`
438+
const url = `/clusters/${owner}/${cluster}/proxy/kubedb.com/${version}/namespaces/${namespace}/mongodbs/${name}`
438439
const resp = await axios.get(url)
439440

440441
setDiscriminatorValue('/dbDetails', resp.data || {})
@@ -810,13 +811,7 @@ export const useFunc = (model) => {
810811
function getMachines(type) {
811812
const presets = storeGet('/kubedbuiPresets') || {}
812813
const dbDetails = getValue(discriminator, '/dbDetails')
813-
// const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {}
814-
const limits = (type === 'replicaSet' || type === 'standalone'
815-
? dbDetails?.spec?.podTemplate?.spec?.resources?.requests
816-
: dbDetails?.spec?.shardTopology?.[type]?.podTemplate?.spec?.resources?.requests) || {
817-
cpu: '',
818-
memory: '',
819-
}
814+
const limits = getLimits(type)
820815

821816
const avlMachines = presets.admin?.machineProfiles?.available || []
822817
let arr = []
@@ -866,13 +861,7 @@ export const useFunc = (model) => {
866861

867862
function setMachine(type) {
868863
const dbDetails = getValue(discriminator, '/dbDetails')
869-
// const limits = dbDetails?.spec?.podTemplate?.spec?.resources?.limits || {}
870-
const limits = (type === 'replicaSet' || type === 'standalone'
871-
? dbDetails?.spec?.podTemplate?.spec?.resources?.requests
872-
: dbDetails?.spec?.shardTopology?.[type]?.podTemplate?.spec?.resources?.requests) || {
873-
cpu: '',
874-
memory: '',
875-
}
864+
const limits = getLimits(type)
876865
const annotations = dbDetails?.metadata?.annotations || {}
877866
const instance = annotations['kubernetes.io/instance-type']
878867
let parsedInstance = {}
@@ -894,9 +883,8 @@ export const useFunc = (model) => {
894883
} else return { machine: 'custom', cpu: limits.cpu, memory: limits.memory }
895884
}
896885

897-
function onMachineChange(type, valPath) {
898-
let selectedMachine = {}
899-
selectedMachine = getValue(discriminator, `/machine-${type}`)
886+
function onMachineChange(type) {
887+
const selectedMachine = getValue(discriminator, `/machine-${type}`) || {}
900888
const machine = machinesFromPreset.find((item) => item.id === selectedMachine.machine)
901889

902890
let obj = {}
@@ -1850,27 +1838,9 @@ export const useFunc = (model) => {
18501838
return limitVal
18511839
}
18521840

1853-
function onExporterResourceChange(type) {
1854-
const commitPath = `/spec/verticalScaling/exporter/resources/requests/${type}`
1855-
const valPath = `/spec/verticalScaling/exporter/resources/limits/${type}`
1856-
const val = getValue(model, valPath)
1857-
if (val)
1858-
commit('wizard/model$update', {
1859-
path: commitPath,
1860-
value: val,
1861-
force: true,
1862-
})
1863-
}
1864-
18651841
function isMachineValid(type) {
18661842
const dbDetails = getValue(discriminator, '/dbDetails')
1867-
1868-
const limits = (type === 'replicaSet' || type === 'standalone'
1869-
? dbDetails?.spec?.podTemplate?.spec?.resources?.requests
1870-
: dbDetails?.spec?.shardTopology?.[type]?.podTemplate?.spec?.resources?.requests) || {
1871-
cpu: '',
1872-
memory: '',
1873-
}
1843+
const limits = getLimits(type)
18741844

18751845
const selectedMachine = getValue(discriminator, `/machine-${type}`)
18761846
const selectedLimits = { cpu: selectedMachine.cpu, memory: selectedMachine.memory }
@@ -1881,10 +1851,26 @@ export const useFunc = (model) => {
18811851
return false
18821852
}
18831853

1854+
function getLimits(type) {
1855+
const dbDetails = getValue(discriminator, '/dbDetails')
1856+
const isTopology = !!dbDetails?.spec?.shardTopology
1857+
1858+
const spec = isTopology
1859+
? dbDetails?.spec?.shardTopology?.[type]
1860+
: dbDetails?.spec?.podTemplate?.spec
1861+
let containers = spec?.containers ?? []
1862+
1863+
if (containers.length === 0) {
1864+
if (spec?.resources?.requests) return spec?.resources?.requests
1865+
containers = spec?.podTemplate?.spec?.containers ?? []
1866+
}
1867+
const kind = dbDetails?.kind?.toLowerCase()
1868+
return containers.find((container) => container.name === kind)?.resources?.requests ?? {}
1869+
}
1870+
18841871
return {
18851872
isMachineValid,
18861873
setExporter,
1887-
onExporterResourceChange,
18881874
fetchAliasOptions,
18891875
validateNewCertificates,
18901876
disableAlias,

0 commit comments

Comments
 (0)