Skip to content

Commit 7c23e1a

Browse files
authored
Merge pull request kubernetes#80885 from draveness/feature/update-framework-logger
fix: Use %q instead of %v in the scheduling framework
2 parents 521b5c3 + 22bac30 commit 7c23e1a

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

pkg/scheduler/framework/v1alpha1/framework.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
9090

9191
p, err := factory(pc, f)
9292
if err != nil {
93-
return nil, fmt.Errorf("error initializing plugin %v: %v", name, err)
93+
return nil, fmt.Errorf("error initializing plugin %q: %v", name, err)
9494
}
9595
pluginsMap[name] = p
9696

@@ -107,11 +107,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
107107
if pg, ok := pluginsMap[pf.Name]; ok {
108108
p, ok := pg.(PrefilterPlugin)
109109
if !ok {
110-
return nil, fmt.Errorf("plugin %v does not extend prefilter plugin", pf.Name)
110+
return nil, fmt.Errorf("plugin %q does not extend prefilter plugin", pf.Name)
111111
}
112112
f.prefilterPlugins = append(f.prefilterPlugins, p)
113113
} else {
114-
return nil, fmt.Errorf("prefilter plugin %v does not exist", pf.Name)
114+
return nil, fmt.Errorf("prefilter plugin %q does not exist", pf.Name)
115115
}
116116
}
117117
}
@@ -121,11 +121,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
121121
if pg, ok := pluginsMap[r.Name]; ok {
122122
p, ok := pg.(FilterPlugin)
123123
if !ok {
124-
return nil, fmt.Errorf("plugin %v does not extend filter plugin", r.Name)
124+
return nil, fmt.Errorf("plugin %q does not extend filter plugin", r.Name)
125125
}
126126
f.filterPlugins = append(f.filterPlugins, p)
127127
} else {
128-
return nil, fmt.Errorf("filter plugin %v does not exist", r.Name)
128+
return nil, fmt.Errorf("filter plugin %q does not exist", r.Name)
129129
}
130130
}
131131
}
@@ -136,10 +136,10 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
136136
// First, make sure the plugin implements ScorePlugin interface.
137137
p, ok := pg.(ScorePlugin)
138138
if !ok {
139-
return nil, fmt.Errorf("plugin %v does not extend score plugin", sc.Name)
139+
return nil, fmt.Errorf("plugin %q does not extend score plugin", sc.Name)
140140
}
141141
if f.pluginNameToWeightMap[p.Name()] == 0 {
142-
return nil, fmt.Errorf("score plugin %v is not configured with weight", p.Name())
142+
return nil, fmt.Errorf("score plugin %q is not configured with weight", p.Name())
143143
}
144144
f.scorePlugins = append(f.scorePlugins, p)
145145

@@ -150,7 +150,7 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
150150
f.scoreWithNormalizePlugins = append(f.scoreWithNormalizePlugins, np)
151151
}
152152
} else {
153-
return nil, fmt.Errorf("score plugin %v does not exist", sc.Name)
153+
return nil, fmt.Errorf("score plugin %q does not exist", sc.Name)
154154
}
155155
}
156156
}
@@ -160,11 +160,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
160160
if pg, ok := pluginsMap[r.Name]; ok {
161161
p, ok := pg.(ReservePlugin)
162162
if !ok {
163-
return nil, fmt.Errorf("plugin %v does not extend reserve plugin", r.Name)
163+
return nil, fmt.Errorf("plugin %q does not extend reserve plugin", r.Name)
164164
}
165165
f.reservePlugins = append(f.reservePlugins, p)
166166
} else {
167-
return nil, fmt.Errorf("reserve plugin %v does not exist", r.Name)
167+
return nil, fmt.Errorf("reserve plugin %q does not exist", r.Name)
168168
}
169169
}
170170
}
@@ -174,11 +174,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
174174
if pg, ok := pluginsMap[r.Name]; ok {
175175
p, ok := pg.(PostFilterPlugin)
176176
if !ok {
177-
return nil, fmt.Errorf("plugin %v does not extend post-filter plugin", r.Name)
177+
return nil, fmt.Errorf("plugin %q does not extend post-filter plugin", r.Name)
178178
}
179179
f.postFilterPlugins = append(f.postFilterPlugins, p)
180180
} else {
181-
return nil, fmt.Errorf("post-filter plugin %v does not exist", r.Name)
181+
return nil, fmt.Errorf("post-filter plugin %q does not exist", r.Name)
182182
}
183183
}
184184
}
@@ -188,11 +188,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
188188
if pg, ok := pluginsMap[pb.Name]; ok {
189189
p, ok := pg.(PrebindPlugin)
190190
if !ok {
191-
return nil, fmt.Errorf("plugin %v does not extend prebind plugin", pb.Name)
191+
return nil, fmt.Errorf("plugin %q does not extend prebind plugin", pb.Name)
192192
}
193193
f.prebindPlugins = append(f.prebindPlugins, p)
194194
} else {
195-
return nil, fmt.Errorf("prebind plugin %v does not exist", pb.Name)
195+
return nil, fmt.Errorf("prebind plugin %q does not exist", pb.Name)
196196
}
197197
}
198198
}
@@ -202,11 +202,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
202202
if pg, ok := pluginsMap[pb.Name]; ok {
203203
p, ok := pg.(BindPlugin)
204204
if !ok {
205-
return nil, fmt.Errorf("plugin %v does not extend bind plugin", pb.Name)
205+
return nil, fmt.Errorf("plugin %q does not extend bind plugin", pb.Name)
206206
}
207207
f.bindPlugins = append(f.bindPlugins, p)
208208
} else {
209-
return nil, fmt.Errorf("bind plugin %v does not exist", pb.Name)
209+
return nil, fmt.Errorf("bind plugin %q does not exist", pb.Name)
210210
}
211211
}
212212
}
@@ -216,11 +216,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
216216
if pg, ok := pluginsMap[pb.Name]; ok {
217217
p, ok := pg.(PostbindPlugin)
218218
if !ok {
219-
return nil, fmt.Errorf("plugin %v does not extend postbind plugin", pb.Name)
219+
return nil, fmt.Errorf("plugin %q does not extend postbind plugin", pb.Name)
220220
}
221221
f.postbindPlugins = append(f.postbindPlugins, p)
222222
} else {
223-
return nil, fmt.Errorf("postbind plugin %v does not exist", pb.Name)
223+
return nil, fmt.Errorf("postbind plugin %q does not exist", pb.Name)
224224
}
225225
}
226226
}
@@ -230,11 +230,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
230230
if pg, ok := pluginsMap[ur.Name]; ok {
231231
p, ok := pg.(UnreservePlugin)
232232
if !ok {
233-
return nil, fmt.Errorf("plugin %v does not extend unreserve plugin", ur.Name)
233+
return nil, fmt.Errorf("plugin %q does not extend unreserve plugin", ur.Name)
234234
}
235235
f.unreservePlugins = append(f.unreservePlugins, p)
236236
} else {
237-
return nil, fmt.Errorf("unreserve plugin %v does not exist", ur.Name)
237+
return nil, fmt.Errorf("unreserve plugin %q does not exist", ur.Name)
238238
}
239239
}
240240
}
@@ -244,11 +244,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
244244
if pg, ok := pluginsMap[pr.Name]; ok {
245245
p, ok := pg.(PermitPlugin)
246246
if !ok {
247-
return nil, fmt.Errorf("plugin %v does not extend permit plugin", pr.Name)
247+
return nil, fmt.Errorf("plugin %q does not extend permit plugin", pr.Name)
248248
}
249249
f.permitPlugins = append(f.permitPlugins, p)
250250
} else {
251-
return nil, fmt.Errorf("permit plugin %v does not exist", pr.Name)
251+
return nil, fmt.Errorf("permit plugin %q does not exist", pr.Name)
252252
}
253253
}
254254
}
@@ -258,14 +258,14 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
258258
if pg, ok := pluginsMap[qs.Name]; ok {
259259
p, ok := pg.(QueueSortPlugin)
260260
if !ok {
261-
return nil, fmt.Errorf("plugin %v does not extend queue sort plugin", qs.Name)
261+
return nil, fmt.Errorf("plugin %q does not extend queue sort plugin", qs.Name)
262262
}
263263
f.queueSortPlugins = append(f.queueSortPlugins, p)
264264
if len(f.queueSortPlugins) > 1 {
265265
return nil, fmt.Errorf("only one queue sort plugin can be enabled")
266266
}
267267
} else {
268-
return nil, fmt.Errorf("queue sort plugin %v does not exist", qs.Name)
268+
return nil, fmt.Errorf("queue sort plugin %q does not exist", qs.Name)
269269
}
270270
}
271271
}
@@ -293,11 +293,11 @@ func (f *framework) RunPrefilterPlugins(
293293
status := pl.Prefilter(pc, pod)
294294
if !status.IsSuccess() {
295295
if status.Code() == Unschedulable {
296-
msg := fmt.Sprintf("rejected by %v at prefilter: %v", pl.Name(), status.Message())
296+
msg := fmt.Sprintf("rejected by %q at prefilter: %v", pl.Name(), status.Message())
297297
klog.V(4).Infof(msg)
298298
return NewStatus(status.Code(), msg)
299299
}
300-
msg := fmt.Sprintf("error while running %v prefilter plugin for pod %v: %v", pl.Name(), pod.Name, status.Message())
300+
msg := fmt.Sprintf("error while running %q prefilter plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
301301
klog.Error(msg)
302302
return NewStatus(Error, msg)
303303
}
@@ -316,7 +316,7 @@ func (f *framework) RunFilterPlugins(pc *PluginContext,
316316
status := pl.Filter(pc, pod, nodeName)
317317
if !status.IsSuccess() {
318318
if status.Code() != Unschedulable {
319-
errMsg := fmt.Sprintf("RunFilterPlugins: error while running %v filter plugin for pod %v: %v",
319+
errMsg := fmt.Sprintf("error while running %q filter plugin for pod %q: %v",
320320
pl.Name(), pod.Name, status.Message())
321321
klog.Error(errMsg)
322322
return NewStatus(Error, errMsg)
@@ -340,7 +340,7 @@ func (f *framework) RunPostFilterPlugins(
340340
for _, pl := range f.postFilterPlugins {
341341
status := pl.PostFilter(pc, pod, nodes, filteredNodesStatuses)
342342
if !status.IsSuccess() {
343-
msg := fmt.Sprintf("error while running %v postfilter plugin for pod %v: %v", pl.Name(), pod.Name, status.Message())
343+
msg := fmt.Sprintf("error while running %q postfilter plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
344344
klog.Error(msg)
345345
return NewStatus(Error, msg)
346346
}
@@ -372,7 +372,7 @@ func (f *framework) RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1.
372372
})
373373

374374
if err := errCh.ReceiveError(); err != nil {
375-
msg := fmt.Sprintf("error while running score plugin for pod %v: %v", pod.Name, err)
375+
msg := fmt.Sprintf("error while running score plugin for pod %q: %v", pod.Name, err)
376376
klog.Error(msg)
377377
return nil, NewStatus(Error, msg)
378378
}
@@ -391,20 +391,20 @@ func (f *framework) RunNormalizeScorePlugins(pc *PluginContext, pod *v1.Pod, sco
391391
pl := f.scoreWithNormalizePlugins[index]
392392
nodeScoreList, ok := scores[pl.Name()]
393393
if !ok {
394-
err := fmt.Errorf("normalize score plugin %v has no corresponding scores in the PluginToNodeScoreMap", pl.Name())
394+
err := fmt.Errorf("normalize score plugin %q has no corresponding scores in the PluginToNodeScoreMap", pl.Name())
395395
errCh.SendErrorWithCancel(err, cancel)
396396
return
397397
}
398398
status := pl.NormalizeScore(pc, pod, nodeScoreList)
399399
if !status.IsSuccess() {
400-
err := fmt.Errorf("normalize score plugin %v failed with error %v", pl.Name(), status.Message())
400+
err := fmt.Errorf("normalize score plugin %q failed with error %v", pl.Name(), status.Message())
401401
errCh.SendErrorWithCancel(err, cancel)
402402
return
403403
}
404404
})
405405

406406
if err := errCh.ReceiveError(); err != nil {
407-
msg := fmt.Sprintf("error while running normalize score plugin for pod %v: %v", pod.Name, err)
407+
msg := fmt.Sprintf("error while running normalize score plugin for pod %q: %v", pod.Name, err)
408408
klog.Error(msg)
409409
return NewStatus(Error, msg)
410410
}
@@ -423,7 +423,7 @@ func (f *framework) ApplyScoreWeights(pc *PluginContext, pod *v1.Pod, scores Plu
423423
weight := f.pluginNameToWeightMap[pl.Name()]
424424
nodeScoreList, ok := scores[pl.Name()]
425425
if !ok {
426-
err := fmt.Errorf("score plugin %v has no corresponding scores in the PluginToNodeScoreMap", pl.Name())
426+
err := fmt.Errorf("score plugin %q has no corresponding scores in the PluginToNodeScoreMap", pl.Name())
427427
errCh.SendErrorWithCancel(err, cancel)
428428
return
429429
}
@@ -433,7 +433,7 @@ func (f *framework) ApplyScoreWeights(pc *PluginContext, pod *v1.Pod, scores Plu
433433
})
434434

435435
if err := errCh.ReceiveError(); err != nil {
436-
msg := fmt.Sprintf("error while applying score weights for pod %v: %v", pod.Name, err)
436+
msg := fmt.Sprintf("error while applying score weights for pod %q: %v", pod.Name, err)
437437
klog.Error(msg)
438438
return NewStatus(Error, msg)
439439
}
@@ -450,11 +450,11 @@ func (f *framework) RunPrebindPlugins(
450450
status := pl.Prebind(pc, pod, nodeName)
451451
if !status.IsSuccess() {
452452
if status.Code() == Unschedulable {
453-
msg := fmt.Sprintf("rejected by %v at prebind: %v", pl.Name(), status.Message())
453+
msg := fmt.Sprintf("rejected by %q at prebind: %v", pl.Name(), status.Message())
454454
klog.V(4).Infof(msg)
455455
return NewStatus(status.Code(), msg)
456456
}
457-
msg := fmt.Sprintf("error while running %v prebind plugin for pod %v: %v", pl.Name(), pod.Name, status.Message())
457+
msg := fmt.Sprintf("error while running %q prebind plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
458458
klog.Error(msg)
459459
return NewStatus(Error, msg)
460460
}
@@ -474,7 +474,7 @@ func (f *framework) RunBindPlugins(pc *PluginContext, pod *v1.Pod, nodeName stri
474474
continue
475475
}
476476
if !status.IsSuccess() {
477-
msg := fmt.Sprintf("bind plugin %v failed to bind pod %v/%v: %v", bp.Name(), pod.Namespace, pod.Name, status.Message())
477+
msg := fmt.Sprintf("bind plugin %q failed to bind pod \"%v/%v\": %v", bp.Name(), pod.Namespace, pod.Name, status.Message())
478478
klog.Error(msg)
479479
return NewStatus(Error, msg)
480480
}
@@ -499,7 +499,7 @@ func (f *framework) RunReservePlugins(
499499
for _, pl := range f.reservePlugins {
500500
status := pl.Reserve(pc, pod, nodeName)
501501
if !status.IsSuccess() {
502-
msg := fmt.Sprintf("error while running %v reserve plugin for pod %v: %v", pl.Name(), pod.Name, status.Message())
502+
msg := fmt.Sprintf("error while running %q reserve plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
503503
klog.Error(msg)
504504
return NewStatus(Error, msg)
505505
}
@@ -530,7 +530,7 @@ func (f *framework) RunPermitPlugins(
530530
status, d := pl.Permit(pc, pod, nodeName)
531531
if !status.IsSuccess() {
532532
if status.Code() == Unschedulable {
533-
msg := fmt.Sprintf("rejected by %v at permit: %v", pl.Name(), status.Message())
533+
msg := fmt.Sprintf("rejected by %q at permit: %v", pl.Name(), status.Message())
534534
klog.V(4).Infof(msg)
535535
return NewStatus(status.Code(), msg)
536536
}
@@ -541,7 +541,7 @@ func (f *framework) RunPermitPlugins(
541541
}
542542
statusCode = Wait
543543
} else {
544-
msg := fmt.Sprintf("error while running %v permit plugin for pod %v: %v", pl.Name(), pod.Name, status.Message())
544+
msg := fmt.Sprintf("error while running %q permit plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
545545
klog.Error(msg)
546546
return NewStatus(Error, msg)
547547
}
@@ -555,10 +555,10 @@ func (f *framework) RunPermitPlugins(
555555
f.waitingPods.add(w)
556556
defer f.waitingPods.remove(pod.UID)
557557
timer := time.NewTimer(timeout)
558-
klog.V(4).Infof("waiting for %v for pod %v at permit", timeout, pod.Name)
558+
klog.V(4).Infof("waiting for %v for pod %q at permit", timeout, pod.Name)
559559
select {
560560
case <-timer.C:
561-
msg := fmt.Sprintf("pod %v rejected due to timeout after waiting %v at permit", pod.Name, timeout)
561+
msg := fmt.Sprintf("pod %q rejected due to timeout after waiting %v at permit", pod.Name, timeout)
562562
klog.V(4).Infof(msg)
563563
return NewStatus(Unschedulable, msg)
564564
case s := <-w.s:
@@ -568,7 +568,7 @@ func (f *framework) RunPermitPlugins(
568568
klog.V(4).Infof(msg)
569569
return NewStatus(s.Code(), msg)
570570
}
571-
msg := fmt.Sprintf("error received while waiting at permit for pod %v: %v", pod.Name, s.Message())
571+
msg := fmt.Sprintf("error received while waiting at permit for pod %q: %v", pod.Name, s.Message())
572572
klog.Error(msg)
573573
return NewStatus(Error, msg)
574574
}

0 commit comments

Comments
 (0)