From 3450620583f267bfe39ab1d7770daaa8ec6c71d2 Mon Sep 17 00:00:00 2001 From: ioito Date: Tue, 19 Dec 2023 13:24:46 +0800 Subject: [PATCH] fix(region): avoid rds vcpu count is zero --- pkg/compute/models/dbinstances.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/compute/models/dbinstances.go b/pkg/compute/models/dbinstances.go index 92def6fffaf..47457612bbb 100644 --- a/pkg/compute/models/dbinstances.go +++ b/pkg/compute/models/dbinstances.go @@ -1673,8 +1673,21 @@ func (self *SDBInstance) SyncWithCloudDBInstance(ctx context.Context, userCred m self.Engine = ext.GetEngine() self.EngineVersion = ext.GetEngineVersion() self.InstanceType = ext.GetInstanceType() - self.VcpuCount = ext.GetVcpuCount() - self.VmemSizeMb = ext.GetVmemSizeMB() + cpu := ext.GetVcpuCount() + mem := ext.GetVmemSizeMB() + if (cpu == 0 || mem == 0) && len(self.InstanceType) > 0 { + skus, _ := self.GetAvailableDBInstanceSkus(true) + for _, sku := range skus { + cpu, mem = sku.VcpuCount, sku.VmemSizeMb + break + } + } + if cpu > 0 { + self.VcpuCount = cpu + } + if mem > 0 { + self.VmemSizeMb = mem + } self.DiskSizeGB = ext.GetDiskSizeGB() self.DiskSizeUsedMB = ext.GetDiskSizeUsedMB() self.StorageType = ext.GetStorageType()