@@ -42,13 +42,13 @@ func GetLocalCache() *QuotaManager {
42
42
return & localCache
43
43
}
44
44
45
+ var once sync.Once
45
46
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
+ })
52
52
return & localCache
53
53
}
54
54
@@ -68,15 +68,15 @@ func (q *QuotaManager) FitQuota(ns string, memreq int64, coresreq int64, deviceN
68
68
coreResourceName := resourceNames .ResourceCoreName
69
69
_ , ok = (* dq )[memResourceName ]
70
70
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 )
72
72
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 )
74
74
return false
75
75
}
76
76
}
77
77
_ , ok = (* dq )[coreResourceName ]
78
78
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 )
80
80
return false
81
81
}
82
82
return true
@@ -133,7 +133,7 @@ func (q *QuotaManager) AddUsage(pod *corev1.Pod, podDev PodDevices) {
133
133
}
134
134
for _ , val := range q .Quotas {
135
135
for idx , val1 := range * val {
136
- klog .Infoln ("add usage val=" , idx , ":" , val1 )
136
+ klog .V ( 4 ). Infoln ("add usage val=" , idx , ":" , val1 )
137
137
}
138
138
}
139
139
}
@@ -157,7 +157,7 @@ func (q *QuotaManager) RmUsage(pod *corev1.Pod, podDev PodDevices) {
157
157
}
158
158
for _ , val := range q .Quotas {
159
159
for idx , val1 := range * val {
160
- klog .Infoln ("after val=" , idx , ":" , val1 )
160
+ klog .V ( 4 ). Infoln ("after val=" , idx , ":" , val1 )
161
161
}
162
162
}
163
163
}
@@ -181,10 +181,10 @@ func (q *QuotaManager) AddQuota(quota *corev1.ResourceQuota) {
181
181
for idx , val := range quota .Spec .Hard {
182
182
value , ok := val .AsInt64 ()
183
183
if ok {
184
- if len (idx .String ()) <= len ( "limits." ) {
184
+ if ! strings . HasPrefix (idx .String (), "limits." ) {
185
185
continue
186
186
}
187
- dn := idx .String ()[ len ( "limits." ):]
187
+ dn := strings . TrimPrefix ( idx .String (), "limits." )
188
188
if ! IsManagedQuota (dn ) {
189
189
continue
190
190
}
@@ -200,12 +200,12 @@ func (q *QuotaManager) AddQuota(quota *corev1.ResourceQuota) {
200
200
}
201
201
}
202
202
(* dp )[dn ].Limit = value
203
- klog .InfoS ("quota set:" , "idx=" , idx , "val" , value )
203
+ klog .V ( 4 ). InfoS ("quota set:" , "idx=" , idx , "val" , value )
204
204
}
205
205
}
206
206
for _ , val := range q .Quotas {
207
207
for idx , val1 := range * val {
208
- klog .Infoln ("after val=" , idx , ":" , val1 )
208
+ klog .V ( 4 ). Infoln ("after val=" , idx , ":" , val1 )
209
209
}
210
210
}
211
211
}
@@ -223,13 +223,17 @@ func (q *QuotaManager) DelQuota(quota *corev1.ResourceQuota) {
223
223
if ! IsManagedQuota (dn ) {
224
224
continue
225
225
}
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
+ }
228
232
}
229
233
}
230
234
for _ , val := range q .Quotas {
231
235
for idx , val1 := range * val {
232
- klog .Infoln ("after val=" , idx , ":" , val1 )
236
+ klog .V ( 4 ). Infoln ("after val=" , idx , ":" , val1 )
233
237
}
234
238
}
235
239
0 commit comments