Skip to content

Commit

Permalink
fix(obcluster): prevent negtive remain resource
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Mar 26, 2024
1 parent 8c3e7ac commit 192b81f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions internal/dashboard/business/oceanbase/obcluster_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ See the Mulan PSL v2 for more details.
package oceanbase

import (
"cmp"

Check failure on line 16 in internal/dashboard/business/oceanbase/obcluster_usage.go

View workflow job for this annotation

GitHub Actions / build-images

package cmp is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/cmp)
"context"

"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -94,10 +95,10 @@ func getServerUsages(gvservers []model.GVOBServer) ([]response.OBServerAvailable
zoneResource := &response.OBZoneAvaiableResource{
ServerCount: 1,
OBZone: gvserver.Zone,
AvailableCPU: gvserver.CPUCapacity - gvserver.CPUAssigned,
AvailableMemory: gvserver.MemCapacity - gvserver.MemAssigned,
AvailableLogDisk: gvserver.LogDiskCapacity - gvserver.LogDiskAssigned,
AvailableDataDisk: gvserver.DataDiskCapacity - gvserver.DataDiskAllocated,
AvailableCPU: max(gvserver.CPUCapacity-gvserver.CPUAssigned, 0),
AvailableMemory: max(gvserver.MemCapacity-gvserver.MemAssigned, 0),
AvailableLogDisk: max(gvserver.LogDiskCapacity-gvserver.LogDiskAssigned, 0),
AvailableDataDisk: max(gvserver.DataDiskCapacity-gvserver.DataDiskAllocated, 0),
}
serverUsage := response.OBServerAvailableResource{
OBServerIP: gvserver.ServerIP,
Expand All @@ -124,3 +125,10 @@ func getServerUsages(gvservers []model.GVOBServer) ([]response.OBServerAvailable
}
return serverUsages, zoneMapping
}

func max[t cmp.Ordered](a, b t) t {
if a > b {

Check failure on line 130 in internal/dashboard/business/oceanbase/obcluster_usage.go

View workflow job for this annotation

GitHub Actions / lint

invalid operation: a > b (type parameter t is not comparable with >) (typecheck)
return a
}
return b
}

0 comments on commit 192b81f

Please sign in to comment.