Skip to content

Commit 6b1374c

Browse files
committed
resolve comment
1 parent 0667a39 commit 6b1374c

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

pkg/device/nvidia/device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ func fitQuota(tmpDevs map[string]device.ContainerDevices, ns string, memreq int6
610610
mem += int64(val.Usedmem)
611611
core += int64(val.Usedcores)
612612
}
613-
klog.Infoln("Allocating...", mem, "cores", core)
613+
klog.V(4).Infoln("Allocating...", mem, "cores", core)
614614
return device.GetLocalCache().FitQuota(ns, mem, core, NvidiaGPUDevice)
615615
}
616616

pkg/device/quota.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ func GetLocalCache() *QuotaManager {
4242
return &localCache
4343
}
4444

45+
var once sync.Once
4546
func NewQuotaManager() *QuotaManager {
46-
if localCache.Quotas != nil {
47-
return &localCache
48-
}
49-
localCache = QuotaManager{
50-
Quotas: make(map[string]*DeviceQuota),
51-
}
47+
once.Do(func() {
48+
localCache = QuotaManager{
49+
Quotas: make(map[string]*DeviceQuota),
50+
}
51+
})
5252
return &localCache
5353
}
5454

@@ -68,15 +68,15 @@ func (q *QuotaManager) FitQuota(ns string, memreq int64, coresreq int64, deviceN
6868
coreResourceName := resourceNames.ResourceCoreName
6969
_, ok = (*dq)[memResourceName]
7070
if ok {
71-
klog.InfoS("resourceMem quota judging", "limit", (*dq)[memResourceName].Limit, "used", (*dq)[memResourceName].Used, "alloc", memreq)
71+
klog.V(4).InfoS("resourceMem quota judging", "limit", (*dq)[memResourceName].Limit, "used", (*dq)[memResourceName].Used, "alloc", memreq)
7272
if (*dq)[memResourceName].Limit != 0 && (*dq)[memResourceName].Used+memreq > (*dq)[memResourceName].Limit {
73-
klog.InfoS("resourceMem quota not fitted", "limit", (*dq)[memResourceName].Limit, "used", (*dq)[memResourceName].Used, "alloc", memreq)
73+
klog.V(4).InfoS("resourceMem quota not fitted", "limit", (*dq)[memResourceName].Limit, "used", (*dq)[memResourceName].Used, "alloc", memreq)
7474
return false
7575
}
7676
}
7777
_, ok = (*dq)[coreResourceName]
7878
if ok && (*dq)[coreResourceName].Limit != 0 && (*dq)[coreResourceName].Used+coresreq > (*dq)[coreResourceName].Limit {
79-
klog.InfoS("resourceCores quota not fitted", "limit", (*dq)[coreResourceName].Limit, "used", (*dq)[coreResourceName].Used, "alloc", memreq)
79+
klog.V(4).InfoS("resourceCores quota not fitted", "limit", (*dq)[coreResourceName].Limit, "used", (*dq)[coreResourceName].Used, "alloc", memreq)
8080
return false
8181
}
8282
return true
@@ -133,7 +133,7 @@ func (q *QuotaManager) AddUsage(pod *corev1.Pod, podDev PodDevices) {
133133
}
134134
for _, val := range q.Quotas {
135135
for idx, val1 := range *val {
136-
klog.Infoln("add usage val=", idx, ":", val1)
136+
klog.V(4).Infoln("add usage val=", idx, ":", val1)
137137
}
138138
}
139139
}
@@ -157,7 +157,7 @@ func (q *QuotaManager) RmUsage(pod *corev1.Pod, podDev PodDevices) {
157157
}
158158
for _, val := range q.Quotas {
159159
for idx, val1 := range *val {
160-
klog.Infoln("after val=", idx, ":", val1)
160+
klog.V(4).Infoln("after val=", idx, ":", val1)
161161
}
162162
}
163163
}
@@ -181,10 +181,10 @@ func (q *QuotaManager) AddQuota(quota *corev1.ResourceQuota) {
181181
for idx, val := range quota.Spec.Hard {
182182
value, ok := val.AsInt64()
183183
if ok {
184-
if len(idx.String()) <= len("limits.") {
184+
if !strings.HasPrefix(idx.String(), "limits.") {
185185
continue
186186
}
187-
dn := idx.String()[len("limits."):]
187+
dn := strings.TrimPrefix(idx.String(), "limits.")
188188
if !IsManagedQuota(dn) {
189189
continue
190190
}
@@ -200,12 +200,12 @@ func (q *QuotaManager) AddQuota(quota *corev1.ResourceQuota) {
200200
}
201201
}
202202
(*dp)[dn].Limit = value
203-
klog.InfoS("quota set:", "idx=", idx, "val", value)
203+
klog.V(4).InfoS("quota set:", "idx=", idx, "val", value)
204204
}
205205
}
206206
for _, val := range q.Quotas {
207207
for idx, val1 := range *val {
208-
klog.Infoln("after val=", idx, ":", val1)
208+
klog.V(4).Infoln("after val=", idx, ":", val1)
209209
}
210210
}
211211
}
@@ -223,13 +223,17 @@ func (q *QuotaManager) DelQuota(quota *corev1.ResourceQuota) {
223223
if !IsManagedQuota(dn) {
224224
continue
225225
}
226-
klog.InfoS("quota remove:", "idx=", idx, "val", value)
227-
(*q.Quotas[quota.Namespace])[dn].Limit = 0
226+
klog.V(4).InfoS("quota remove:", "idx=", idx, "val", value)
227+
if dq, ok := q.Quotas[quota.Namespace]; ok {
228+
if quotaInfo, ok := (*dq)[dn]; ok {
229+
quotaInfo.Limit = 0
230+
}
231+
}
228232
}
229233
}
230234
for _, val := range q.Quotas {
231235
for idx, val1 := range *val {
232-
klog.Infoln("after val=", idx, ":", val1)
236+
klog.V(4).Infoln("after val=", idx, ":", val1)
233237
}
234238
}
235239

pkg/scheduler/scheduler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ func (s *Scheduler) onDelPod(obj any) {
121121
if !ok {
122122
return
123123
}
124-
s.podManager.mutex.Lock()
125-
defer s.podManager.mutex.Unlock()
126124
pi, ok := s.pods[pod.UID]
127125
if ok {
128126
s.quotaManager.RmUsage(pod, pi.Devices)

0 commit comments

Comments
 (0)