@@ -218,7 +218,7 @@ func (w *Webhook) Do(targets map[string]*corev1.Pod, subjects sets.String) *Filt
218
218
219
219
res , err := w .polling (taskId )
220
220
221
- w .recordTime (taskId , res .Message )
221
+ w .recordTime (taskId , res .Message , false )
222
222
223
223
if err != nil {
224
224
newWebhookState .ItemStatus = appendStatus (newWebhookState .ItemStatus , pods , func (po string ) bool {
@@ -304,37 +304,41 @@ func (w *Webhook) Do(targets map[string]*corev1.Pod, subjects sets.String) *Filt
304
304
305
305
// First request
306
306
selfTraceId , res , err := w .query (effectiveSubjects )
307
- taskId := getTaskId (res )
308
- klog .Infof (
309
- "do podtransitionrule webhook [%s], pods: %v, taskId: %s, traceId: %s, resp: %s" ,
310
- w .key (),
311
- effectiveSubjects .List (),
312
- taskId ,
313
- selfTraceId ,
314
- utils .DumpJSON (res ),
315
- )
316
307
if err != nil {
317
308
for eft := range effectiveSubjects {
318
309
rejectedPods [eft ] = fmt .Sprintf (
319
- "fail to do webhook [%s], %v, traceId %s, taskId %s" ,
310
+ "fail to request webhook [%s], %v, traceId %s" ,
320
311
w .key (),
321
312
err ,
322
313
selfTraceId ,
323
- taskId ,
324
314
)
325
315
}
316
+ klog .Errorf (
317
+ "fail to request podtransitionrule webhook [%s], pods: %v, traceId: %s, resp: %s" ,
318
+ w .key (),
319
+ effectiveSubjects .List (),
320
+ selfTraceId ,
321
+ utils .DumpJSON (res ),
322
+ )
326
323
return & FilterResult {
327
324
Passed : checked ,
328
325
Rejected : rejectedPods ,
329
326
Err : err ,
330
327
RuleState : & appsv1alpha1.RuleState {Name : w .RuleName , WebhookStatus : newWebhookState },
331
328
}
332
329
}
333
-
330
+ taskId := getTaskId (res )
331
+ klog .Infof (
332
+ "request podtransitionrule webhook [%s], pods: %v, taskId: %s, traceId: %s, resp: %s" ,
333
+ w .key (),
334
+ effectiveSubjects .List (),
335
+ taskId ,
336
+ selfTraceId ,
337
+ utils .DumpJSON (res ),
338
+ )
334
339
if taskId != "" {
335
- w .recordTime (taskId , res .Message )
340
+ w .recordTime (taskId , res .Message , true )
336
341
}
337
-
338
342
localFinished := sets .NewString (res .FinishedNames ... )
339
343
340
344
if ! res .Success {
@@ -403,17 +407,19 @@ func (w *Webhook) convTaskInfo(infoMap map[string]*appsv1alpha1.TaskInfo) []apps
403
407
return states
404
408
}
405
409
406
- func (w * Webhook ) recordTime (taskId , msg string ) {
410
+ func (w * Webhook ) recordTime (taskId , msg string , isFirst bool ) {
407
411
timeNow := time .Now ()
408
412
newRecord := & appsv1alpha1.TaskInfo {
409
413
TaskId : taskId ,
410
414
BeginTime : & metav1.Time {Time : timeNow },
411
415
LastTime : & metav1.Time {Time : timeNow },
412
416
Message : msg ,
413
417
}
414
- tm := w .getTaskInfo (taskId )
415
- if tm != nil && tm .BeginTime != nil {
416
- newRecord .BeginTime = tm .BeginTime .DeepCopy ()
418
+ if ! isFirst {
419
+ tm := w .getTaskInfo (taskId )
420
+ if tm != nil && tm .BeginTime != nil {
421
+ newRecord .BeginTime = tm .BeginTime .DeepCopy ()
422
+ }
417
423
}
418
424
w .taskInfo [taskId ] = newRecord
419
425
}
@@ -527,7 +533,7 @@ func shouldPoll(resp *appsv1alpha1.WebhookResponse) bool {
527
533
}
528
534
529
535
func getTaskId (resp * appsv1alpha1.WebhookResponse ) string {
530
- if resp .Async || resp .Poll {
536
+ if resp != nil && ( resp .Async || resp .Poll ) {
531
537
if resp .TaskId != "" {
532
538
return resp .TaskId
533
539
}
0 commit comments