Skip to content

Commit f65da88

Browse files
committed
Port pod interval test json files and fix resulting bugs
1 parent 5aef7a3 commit f65da88

File tree

21 files changed

+1424
-427
lines changed

21 files changed

+1424
-427
lines changed

pkg/monitor/monitorapi/identification_pod.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ func LocatePod(pod *corev1.Pod) string {
1313
return fmt.Sprintf("ns/%s pod/%s node/%s uid/%s", pod.Namespace, pod.Name, pod.Spec.NodeName, pod.UID)
1414
}
1515

16-
func LocatePodContainer(pod *corev1.Pod, containerName string) string {
17-
return fmt.Sprintf("ns/%s pod/%s node/%s uid/%s container/%s", pod.Namespace, pod.Name, pod.Spec.NodeName, pod.UID, containerName)
18-
}
19-
2016
// NonUniquePodLocatorFrom produces an inexact locator based on namespace and name. This is useful when dealing with events
2117
// that are produced that do not contain UIDs. Ultimately, we should use UIDs everywhere, but this is will keep some our
2218
// matching working until then.
@@ -26,6 +22,7 @@ func NonUniquePodLocatorFrom(locator string) string {
2622
return fmt.Sprintf("ns/%s pod/%s", namespace, parts["pod"])
2723
}
2824

25+
// TODO: all callers should eventuall be using structured locator variant below:
2926
func PodFrom(locator string) PodReference {
3027
parts := LocatorParts(locator)
3128
namespace := NamespaceFrom(parts)
@@ -43,10 +40,27 @@ func PodFrom(locator string) PodReference {
4340
}
4441
}
4542

46-
func ContainerFrom(locator string) ContainerReference {
47-
pod := PodFrom(locator)
48-
parts := LocatorParts(locator)
49-
name := parts["container"]
43+
// PodFromLocator is used to strip down a locator to just a pod. (as it may contain additional keys like container or node)
44+
// that we do not want for some uses.
45+
func PodFromLocator(locator Locator) PodReference {
46+
namespace := locator.Keys[LocatorNamespaceKey]
47+
name := locator.Keys[LocatorPodKey]
48+
uid := locator.Keys[LocatorUIDKey]
49+
if len(namespace) == 0 || len(name) == 0 {
50+
return PodReference{}
51+
}
52+
return PodReference{
53+
NamespacedReference: NamespacedReference{
54+
Namespace: namespace,
55+
Name: name,
56+
UID: uid,
57+
},
58+
}
59+
}
60+
61+
func ContainerFrom(locator Locator) ContainerReference {
62+
pod := PodFrom(locator.OldLocator())
63+
name := locator.Keys[LocatorContainerKey]
5064
if len(name) == 0 || len(pod.UID) == 0 {
5165
return ContainerReference{}
5266
}
@@ -61,17 +75,17 @@ type PodReference struct {
6175
NamespacedReference
6276
}
6377

64-
func (r PodReference) ToLocator() string {
65-
return fmt.Sprintf("ns/%s pod/%s uid/%s", r.Namespace, r.Name, r.UID)
78+
func (r PodReference) ToLocator() Locator {
79+
return NewLocator().PodFromNames(r.Namespace, r.Name, r.UID)
6680
}
6781

6882
type ContainerReference struct {
6983
Pod PodReference
7084
ContainerName string
7185
}
7286

73-
func (r ContainerReference) ToLocator() string {
74-
return fmt.Sprintf("ns/%s pod/%s uid/%s container/%s", r.Pod.Namespace, r.Pod.Name, r.Pod.UID, r.ContainerName)
87+
func (r ContainerReference) ToLocator() Locator {
88+
return NewLocator().ContainerFromNames(r.Pod.Namespace, r.Pod.Name, r.Pod.UID, r.ContainerName)
7589
}
7690

7791
func AnnotationsFromMessage(message string) map[AnnotationKey]string {

pkg/monitor/monitorapi/types.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,26 +370,18 @@ 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])
376373
switch d := intervals[i].From.Sub(intervals[j].From); {
377374
case d < 0:
378-
fmt.Println(" from less than, returning true")
379375
return true
380376
case d > 0:
381-
fmt.Println(" from greater than, returning false")
382377
return false
383378
}
384379
switch d := intervals[i].To.Sub(intervals[j].To); {
385380
case d < 0:
386-
fmt.Println(" to less than, returning true")
387381
return true
388382
case d > 0:
389-
fmt.Println(" to greater than, returning false")
390383
return false
391384
}
392-
fmt.Printf(" falling back to message comparison: %v\n", intervals[i].Message < intervals[j].Message)
393385
return intervals[i].Message < intervals[j].Message
394386
}
395387
func (intervals Intervals) Len() int { return len(intervals) }

pkg/monitortestlibrary/statetracker/state_tracker.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ func (t *stateTracker) CloseInterval(locator monitorapi.Locator, state StateInfo
148148
if !hasCondition {
149149
return nil
150150
}
151-
// TODO: from/to and Build needed?
152151
return []monitorapi.Interval{ib.Build(from, to)}
153152
}
154153

0 commit comments

Comments
 (0)