Skip to content

Commit

Permalink
Fixed some problems found in testing for dashboard 0.3.1 (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI authored Sep 3, 2024
1 parent 39e9750 commit 568cf74
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 30 deletions.
36 changes: 30 additions & 6 deletions internal/dashboard/business/oceanbase/obtenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package oceanbase
import (
"context"
"errors"
"math"
"sort"
"strings"

Expand Down Expand Up @@ -79,6 +80,17 @@ func buildOBTenantApiType(nn types.NamespacedName, p *param.CreateOBTenantParam)
if err != nil {
return nil, oberr.NewBadRequest("invalid log disk size: " + err.Error())
}
var maxIops, minIops int
if p.UnitConfig.MaxIops > math.MaxInt32 {
maxIops = math.MaxInt32
} else {
maxIops = int(p.UnitConfig.MaxIops)
}
if p.UnitConfig.MinIops > math.MaxInt32 {
minIops = math.MaxInt32
} else {
minIops = int(p.UnitConfig.MinIops)
}

t.Spec.Pools = make([]v1alpha1.ResourcePoolSpec, 0, len(p.Pools))
for i := range p.Pools {
Expand All @@ -98,8 +110,8 @@ func buildOBTenantApiType(nn types.NamespacedName, p *param.CreateOBTenantParam)
MemorySize: memorySize,
MinCPU: cpuCount,
LogDiskSize: logDiskSize,
MaxIops: p.UnitConfig.MaxIops,
MinIops: p.UnitConfig.MinIops,
MaxIops: maxIops,
MinIops: minIops,
IopsWeight: p.UnitConfig.IopsWeight,
}
t.Spec.Pools = append(t.Spec.Pools, apiPool)
Expand Down Expand Up @@ -184,8 +196,8 @@ func buildOverviewFromApiType(t *v1alpha1.OBTenant) *response.OBTenantOverview {
if pool.UnitConfig != nil {
replica.MaxCPU = pool.UnitConfig.MaxCPU.Value()
replica.MinCPU = pool.UnitConfig.MinCPU.Value()
replica.MaxIops = pool.UnitConfig.MaxIops
replica.MinIops = pool.UnitConfig.MinIops
replica.MaxIops = int64(pool.UnitConfig.MaxIops)
replica.MinIops = int64(pool.UnitConfig.MinIops)
replica.IopsWeight = pool.UnitConfig.IopsWeight
replica.MemorySize = pool.UnitConfig.MemorySize.Value()
replica.LogDiskSize = pool.UnitConfig.LogDiskSize.Value()
Expand Down Expand Up @@ -552,6 +564,18 @@ func PatchTenant(ctx context.Context, nn types.NamespacedName, p *param.PatchTen
if err != nil {
return nil, oberr.NewBadRequest("invalid log disk size: " + err.Error())
}
var maxIops, minIops int
if p.UnitConfig.UnitConfig.MaxIops > math.MaxInt32 {
maxIops = math.MaxInt32
} else {
maxIops = int(p.UnitConfig.UnitConfig.MaxIops)
}
if p.UnitConfig.UnitConfig.MinIops > math.MaxInt32 {
minIops = math.MaxInt32
} else {
minIops = int(p.UnitConfig.UnitConfig.MinIops)
}

for _, pool := range p.UnitConfig.Pools {
for i := range tenant.Spec.Pools {
if tenant.Spec.Pools[i].Zone == pool.Zone {
Expand All @@ -562,8 +586,8 @@ func PatchTenant(ctx context.Context, nn types.NamespacedName, p *param.PatchTen
MemorySize: memorySize,
MinCPU: cpuCount,
IopsWeight: p.UnitConfig.UnitConfig.IopsWeight,
MaxIops: p.UnitConfig.UnitConfig.MaxIops,
MinIops: p.UnitConfig.UnitConfig.MinIops,
MaxIops: maxIops,
MinIops: minIops,
LogDiskSize: logDiskSize,
}
break
Expand Down
28 changes: 24 additions & 4 deletions internal/dashboard/business/oceanbase/obtenant_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package oceanbase

import (
"context"
"math"

"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -55,6 +56,13 @@ func CreateTenantPool(ctx context.Context, nn param.TenantPoolName, p *param.Ten
if err != nil {
return nil, err
}
var maxIops int
if p.UnitConfig.MaxIops > math.MaxInt32 {
maxIops = math.MaxInt32
} else {
maxIops = int(p.UnitConfig.MaxIops)
}

for _, zone := range clusterCR.Spec.Topology {
if zone.Zone == nn.ZoneName {
tenantCR.Spec.Pools = append(tenantCR.Spec.Pools, v1alpha1.ResourcePoolSpec{
Expand All @@ -69,8 +77,8 @@ func CreateTenantPool(ctx context.Context, nn param.TenantPoolName, p *param.Ten
MaxCPU: cpuCount,
MemorySize: memorySize,
MinCPU: cpuCount,
MaxIops: p.UnitConfig.MaxIops,
MinIops: p.UnitConfig.MaxIops,
MaxIops: maxIops,
MinIops: maxIops,
IopsWeight: p.UnitConfig.IopsWeight,
LogDiskSize: logDiskSize,
},
Expand Down Expand Up @@ -126,6 +134,18 @@ func PatchTenantPool(ctx context.Context, nn param.TenantPoolName, p *param.Tena
if err != nil {
return nil, err
}
var maxIops, minIops int
if p.UnitConfig.MaxIops > math.MaxInt32 {
maxIops = math.MaxInt32
} else {
maxIops = int(p.UnitConfig.MaxIops)
}
if p.UnitConfig.MinIops > math.MaxInt32 {
minIops = math.MaxInt32
} else {
minIops = int(p.UnitConfig.MinIops)
}

for i, pool := range tenantCR.Spec.Pools {
if pool.Zone == nn.ZoneName {
tenantCR.Spec.Pools[i].Priority = p.Priority
Expand All @@ -141,10 +161,10 @@ func PatchTenantPool(ctx context.Context, nn param.TenantPoolName, p *param.Tena
tenantCR.Spec.Pools[i].UnitConfig.LogDiskSize = logDiskSize
}
if p.UnitConfig.MaxIops != 0 {
tenantCR.Spec.Pools[i].UnitConfig.MaxIops = p.UnitConfig.MaxIops
tenantCR.Spec.Pools[i].UnitConfig.MaxIops = maxIops
}
if p.UnitConfig.MinIops != 0 {
tenantCR.Spec.Pools[i].UnitConfig.MinIops = p.UnitConfig.MinIops
tenantCR.Spec.Pools[i].UnitConfig.MinIops = minIops
}
if p.UnitConfig.IopsWeight != 0 {
tenantCR.Spec.Pools[i].UnitConfig.IopsWeight = p.UnitConfig.IopsWeight
Expand Down
Loading

0 comments on commit 568cf74

Please sign in to comment.