Skip to content

Commit 6ec102f

Browse files
committed
Fix missing GracefulDelete
1 parent 9eed005 commit 6ec102f

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

pkg/monitor/monitorapi/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,18 +370,26 @@ type Intervals []Interval
370370
var _ sort.Interface = Intervals{}
371371

372372
func (intervals Intervals) Less(i, j int) bool {
373+
fmt.Printf("comparing\n")
374+
fmt.Printf(" %+v\n", intervals[i])
375+
fmt.Printf(" %+v\n", intervals[j])
373376
switch d := intervals[i].From.Sub(intervals[j].From); {
374377
case d < 0:
378+
fmt.Println(" from less than, returning true")
375379
return true
376380
case d > 0:
381+
fmt.Println(" from greater than, returning false")
377382
return false
378383
}
379384
switch d := intervals[i].To.Sub(intervals[j].To); {
380385
case d < 0:
386+
fmt.Println(" to less than, returning true")
381387
return true
382388
case d > 0:
389+
fmt.Println(" to greater than, returning false")
383390
return false
384391
}
392+
fmt.Printf(" falling back to message comparison: %v\n", intervals[i].Message < intervals[j].Message)
385393
return intervals[i].Message < intervals[j].Message
386394
}
387395
func (intervals Intervals) Len() int { return len(intervals) }

pkg/monitortests/node/watchpods/compute_intervals.go

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func createPodIntervalsFromInstants(input monitorapi.Intervals, recordedResource
8989
continue
9090
}
9191

92-
if event.StructuredMessage.Reason == monitorapi.TerminationStateCleared {
93-
fmt.Println("hi")
92+
if event.StructuredMessage.Reason == monitorapi.PodReasonGracefulDeleteStarted {
93+
fmt.Println("GraceFUlDelete")
9494
}
9595

9696
// We have to strip out container, this needs to be just pod locator here
@@ -152,7 +152,7 @@ func createPodIntervalsFromInstants(input monitorapi.Intervals, recordedResource
152152
monitorapi.PodReasonCreated, monitorapi.PodReasonDeleted, podTimeBounder)...,
153153
)
154154
for _, i := range ret {
155-
if i.StructuredMessage.Reason == monitorapi.TerminationStateCleared {
155+
if i.StructuredMessage.Reason == monitorapi.PodReasonScheduled {
156156
fmt.Println("bingo 1")
157157
}
158158
}
@@ -161,7 +161,7 @@ func createPodIntervalsFromInstants(input monitorapi.Intervals, recordedResource
161161
monitorapi.ContainerReasonContainerWait, monitorapi.ContainerReasonContainerExit, containerTimeBounder)...,
162162
)
163163
for _, i := range ret {
164-
if i.StructuredMessage.Reason == monitorapi.TerminationStateCleared {
164+
if i.StructuredMessage.Reason == monitorapi.PodReasonScheduled {
165165
fmt.Println("bingo 2")
166166
}
167167
}
@@ -170,7 +170,7 @@ func createPodIntervalsFromInstants(input monitorapi.Intervals, recordedResource
170170
monitorapi.ContainerReasonNotReady, "", containerReadinessTimeBounder)...,
171171
)
172172
for _, i := range ret {
173-
if i.StructuredMessage.Reason == monitorapi.TerminationStateCleared {
173+
if i.StructuredMessage.Reason == monitorapi.PodReasonScheduled {
174174
fmt.Println("bingo 3")
175175
}
176176
}
@@ -194,7 +194,6 @@ func createPodIntervalsFromInstants(input monitorapi.Intervals, recordedResource
194194
}
195195
}
196196

197-
fmt.Println("########### Sorting")
198197
sort.Stable(ret)
199198
return ret
200199
}
@@ -410,10 +409,9 @@ type containerLifecycleTimeBounder struct {
410409
}
411410

412411
func (t containerLifecycleTimeBounder) getStartTime(inLocator string) time.Time {
413-
locator := monitorapi.ContainerFrom(inLocator).ToLocator()
414-
containerEvents, ok := t.podToContainerToLifecycleTransitions[locator]
412+
containerEvents, ok := t.podToContainerToLifecycleTransitions[inLocator]
415413
if !ok {
416-
return t.delegate.getStartTime(locator)
414+
return t.delegate.getStartTime(inLocator)
417415
}
418416
for _, event := range containerEvents {
419417
if monitorapi.ReasonFrom(event.Message) == monitorapi.ContainerReasonContainerWait {
@@ -422,7 +420,7 @@ func (t containerLifecycleTimeBounder) getStartTime(inLocator string) time.Time
422420
}
423421

424422
// no hit, try to bound based on pod
425-
return t.delegate.getStartTime(locator)
423+
return t.delegate.getStartTime(inLocator)
426424
}
427425

428426
func (t containerLifecycleTimeBounder) getEndTime(inLocator string) time.Time {
@@ -431,10 +429,9 @@ func (t containerLifecycleTimeBounder) getEndTime(inLocator string) time.Time {
431429
return *containerTermination
432430
}
433431

434-
locator := monitorapi.ContainerFrom(inLocator).ToLocator()
435-
containerEvents, ok := t.podToContainerToLifecycleTransitions[locator]
432+
containerEvents, ok := t.podToContainerToLifecycleTransitions[inLocator]
436433
if !ok {
437-
return t.delegate.getEndTime(locator)
434+
return t.delegate.getEndTime(inLocator)
438435
}
439436
// if the last event is a containerExit, then that's as long as the container lasted.
440437
// if the last event isn't a containerExit, then the last time we're aware of for the container is parent.
@@ -444,7 +441,7 @@ func (t containerLifecycleTimeBounder) getEndTime(inLocator string) time.Time {
444441
}
445442

446443
// no hit, try to bound based on pod
447-
return t.delegate.getEndTime(locator)
444+
return t.delegate.getEndTime(inLocator)
448445
}
449446

450447
func (t containerLifecycleTimeBounder) getContainerEnd(inLocator string) *time.Time {
@@ -517,10 +514,9 @@ type containerReadinessTimeBounder struct {
517514
}
518515

519516
func (t containerReadinessTimeBounder) getStartTime(inLocator string) time.Time {
520-
locator := monitorapi.ContainerFrom(inLocator).ToLocator()
521-
containerEvents, ok := t.podToContainerToLifecycleTransitions[locator]
517+
containerEvents, ok := t.podToContainerToLifecycleTransitions[inLocator]
522518
if !ok {
523-
return t.delegate.getStartTime(locator)
519+
return t.delegate.getStartTime(inLocator)
524520
}
525521
for _, event := range containerEvents {
526522
// you can only be ready from the time your container is started.
@@ -530,7 +526,7 @@ func (t containerReadinessTimeBounder) getStartTime(inLocator string) time.Time
530526
}
531527

532528
// no hit, try to bound based on pod
533-
return t.delegate.getStartTime(locator)
529+
return t.delegate.getStartTime(inLocator)
534530
}
535531

536532
func (t containerReadinessTimeBounder) getEndTime(inLocator string) time.Time {
@@ -554,6 +550,9 @@ func buildTransitionsForCategory(locatorToIntervals map[string][]monitorapi.Inte
554550
for i := range instantEvents {
555551
hasPrev := len(prevEvent.Message) > 0
556552
currEvent := instantEvents[i]
553+
if currEvent.StructuredMessage.Reason == monitorapi.PodReasonScheduled {
554+
fmt.Println("lll")
555+
}
557556
currReason := monitorapi.ReasonFrom(currEvent.Message)
558557
prevAnnotations := monitorapi.AnnotationsFromMessage(prevEvent.Message)
559558
prevBareMessage := monitorapi.NonAnnotationMessage(prevEvent.Message)
@@ -637,42 +636,27 @@ func (n ByPodLifecycle) Swap(i, j int) {
637636
}
638637

639638
func (n ByPodLifecycle) Less(i, j int) bool {
640-
fmt.Println("\nComparing")
641-
fmt.Printf(" lhs: %+v\n", n[i])
642-
fmt.Printf(" rhs: %+v\n", n[j])
643-
fmt.Printf(" checking from: %s < %s\n", n[i].From.UTC(), n[j].From.UTC())
644639
switch d := n[i].From.Sub(n[j].From); {
645640
case d < 0:
646-
fmt.Println(" true")
647641
return true
648642
case d > 0:
649-
fmt.Println(" false")
650643
return false
651644
}
652-
fmt.Printf(" from is equal: %s = %s\n", n[i].From.UTC(), n[j].From.UTC())
653645
lhsReason := n[i].StructuredMessage.Reason
654646
rhsReason := n[j].StructuredMessage.Reason
655647

656-
fmt.Println(" checking switch cases")
657648
switch {
658649
case lhsReason == monitorapi.PodReasonCreated && rhsReason == monitorapi.PodReasonScheduled:
659-
fmt.Println(" true Created should come before Scheduled")
660650
return true
661651
case lhsReason == monitorapi.PodReasonScheduled && rhsReason == monitorapi.PodReasonCreated:
662-
fmt.Println(" false Scheduled should come before Created")
663652
return false
664653
}
665654

666-
fmt.Printf(" checking To: %s < %s\n", n[i].To.UTC(), n[j].To.UTC())
667655
switch d := n[i].To.Sub(n[j].To); {
668656
case d < 0:
669-
fmt.Println(" true")
670657
return true
671658
case d > 0:
672-
fmt.Println(" false")
673659
return false
674660
}
675-
// wat?
676-
fmt.Printf(" <: %v\n", n[i].Message < n[j].Message)
677661
return n[i].Message < n[j].Message
678662
}

pkg/monitortests/node/watchpods/podTest/simple/startingEvents.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
}
8484
},
8585
"tempStructuredMessage": {
86-
"reason": "Ready",
86+
"reason": "GracefulDelete",
8787
"cause": "",
8888
"humanMessage": "",
8989
"annotations": {

0 commit comments

Comments
 (0)