Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions charts/kubedbcom-clickhouse-editor/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ export const useFunc = (model) => {

let autoscaleType = ''
let dbDetails = {}
let instance = {}

async function getDbDetails() {
const annotations =
getValue(model, '/resources/autoscalingKubedbComClickHouseAutoscaler/metadata/annotations') ||
{}
instance = annotations['kubernetes.io/instance-type']
const owner = storeGet('/route/params/user') || ''
const cluster = storeGet('/route/params/cluster') || ''

Expand Down Expand Up @@ -225,15 +230,20 @@ export const useFunc = (model) => {
}

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] : ''
const machineName = minmax === 'min' ? mn : mx

if (minmax === 'min') return mn
else return mx
const nodeGroups = getValue(discriminator, '/topologyMachines') || []
const machineData = nodeGroups.find((item) => item.topologyValue === machineName)
if (machineData) {
return {
machine: machineName,
cpu: machineData.allocatable?.cpu,
memory: machineData.allocatable?.memory,
}
}
return { machine: machineName || '', cpu: '', memory: '' }
}

async function getMachines(minmax) {
Expand All @@ -242,16 +252,23 @@ export const useFunc = (model) => {
const dependantPath = `/allowedMachine-${depends}`

// watchDependency(`discriminator#${dependantPath}`)
const dependantMachine = getValue(discriminator, dependantPath)
const dependantMachineObj = getValue(discriminator, dependantPath)
const dependantMachine = dependantMachineObj?.machine || ''

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 }
return {
text,
value: {
machine: item.topologyValue,
cpu: item.allocatable?.cpu,
memory: item.allocatable?.memory,
},
}
})

const filteredMachine = machines?.filter((item, ind) =>
Expand All @@ -266,16 +283,19 @@ export const useFunc = (model) => {
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 minMachineObj = getValue(discriminator, '/allowedMachine-min')
const maxMachineObj = getValue(discriminator, '/allowedMachine-max')
const minMachine = minMachineObj?.machine || ''
const maxMachine = maxMachineObj?.machine || ''
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 minMachineAllocatable = minMachineObj
? { cpu: minMachineObj.cpu, memory: minMachineObj.memory }
: null
const maxMachineAllocatable = maxMachineObj
? { cpu: maxMachineObj.cpu, memory: maxMachineObj.memory }
: null
const allowedPath = `/resources/autoscalingKubedbComClickHouseAutoscaler/spec/compute/${type}`

if (minMachine && maxMachine && instance !== minMaxMachine) {
Expand All @@ -291,7 +311,7 @@ export const useFunc = (model) => {
})
commit('wizard/model$update', {
path: annoPath,
value: { ...annotations },
value: annotations,
force: true,
})
}
Expand Down
Loading
Loading