@@ -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