| ... | ... |
@@ -39,6 +39,10 @@ func FindRestartingPods(g osgraph.Graph, f osgraph.Namer, logsCommandName, secur |
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
for _, containerStatus := range pod.Status.ContainerStatuses {
|
| 42 |
+ containerString := "" |
|
| 43 |
+ if len(pod.Spec.Containers) > 1 {
|
|
| 44 |
+ containerString = fmt.Sprintf("container %q in ", containerStatus.Name)
|
|
| 45 |
+ } |
|
| 42 | 46 |
switch {
|
| 43 | 47 |
case containerCrashLoopBackOff(containerStatus): |
| 44 | 48 |
var suggestion string |
| ... | ... |
@@ -69,7 +73,7 @@ func FindRestartingPods(g osgraph.Graph, f osgraph.Namer, logsCommandName, secur |
| 69 | 69 |
|
| 70 | 70 |
Severity: osgraph.ErrorSeverity, |
| 71 | 71 |
Key: CrashLoopingPodError, |
| 72 |
- Message: fmt.Sprintf("container %q in %s is crash-looping", containerStatus.Name,
|
|
| 72 |
+ Message: fmt.Sprintf("%s%s is crash-looping", containerString,
|
|
| 73 | 73 |
f.ResourceName(podNode)), |
| 74 | 74 |
Suggestion: osgraph.Suggestion(suggestion), |
| 75 | 75 |
}) |
| ... | ... |
@@ -79,7 +83,7 @@ func FindRestartingPods(g osgraph.Graph, f osgraph.Namer, logsCommandName, secur |
| 79 | 79 |
|
| 80 | 80 |
Severity: osgraph.WarningSeverity, |
| 81 | 81 |
Key: RestartingPodWarning, |
| 82 |
- Message: fmt.Sprintf("container %q in %s has restarted within the last 10 minutes", containerStatus.Name,
|
|
| 82 |
+ Message: fmt.Sprintf("%s%s has restarted within the last 10 minutes", containerString,
|
|
| 83 | 83 |
f.ResourceName(podNode)), |
| 84 | 84 |
}) |
| 85 | 85 |
case containerRestartedFrequently(containerStatus): |
| ... | ... |
@@ -88,7 +92,7 @@ func FindRestartingPods(g osgraph.Graph, f osgraph.Namer, logsCommandName, secur |
| 88 | 88 |
|
| 89 | 89 |
Severity: osgraph.WarningSeverity, |
| 90 | 90 |
Key: RestartingPodWarning, |
| 91 |
- Message: fmt.Sprintf("container %q in %s has restarted %d times", containerStatus.Name,
|
|
| 91 |
+ Message: fmt.Sprintf("%s%s has restarted %d times", containerString,
|
|
| 92 | 92 |
f.ResourceName(podNode), containerStatus.RestartCount), |
| 93 | 93 |
}) |
| 94 | 94 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package analysis |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"sort" |
| 5 |
+ "strings" |
|
| 5 | 6 |
"testing" |
| 6 | 7 |
"time" |
| 7 | 8 |
|
| ... | ... |
@@ -38,6 +39,20 @@ func TestRestartingPodWarning(t *testing.T) {
|
| 38 | 38 |
t.Fatalf("expected %v, got %v", e, a)
|
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 |
+ sort.Sort(osgraph.ByNodeID(markers)) |
|
| 42 |
+ if !strings.HasPrefix(markers[0].Message, "container ") {
|
|
| 43 |
+ t.Fatalf("message %q should state container", markers[0].Message)
|
|
| 44 |
+ } |
|
| 45 |
+ if !strings.HasPrefix(markers[1].Message, "container ") {
|
|
| 46 |
+ t.Fatalf("message %q should state container", markers[1].Message)
|
|
| 47 |
+ } |
|
| 48 |
+ if !strings.HasPrefix(markers[2].Message, "container ") {
|
|
| 49 |
+ t.Fatalf("message %q should state container", markers[2].Message)
|
|
| 50 |
+ } |
|
| 51 |
+ if strings.HasPrefix(markers[3].Message, "container ") {
|
|
| 52 |
+ t.Fatalf("message %q should not state container", markers[3].Message)
|
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 41 | 55 |
future, _ := time.Parse(time.RFC3339, "2015-07-13T19:46:06Z") |
| 42 | 56 |
nowFn = func() unversioned.Time { return unversioned.NewTime(future.UTC()) }
|
| 43 | 57 |
markers = FindRestartingPods(g, osgraph.DefaultNamer, "oc logs", "oadm policy") |
| ... | ... |
@@ -54,4 +69,15 @@ func TestRestartingPodWarning(t *testing.T) {
|
| 54 | 54 |
if e, a := RestartingPodWarning, markers[2].Key; e != a {
|
| 55 | 55 |
t.Fatalf("expected %v, got %v", e, a)
|
| 56 | 56 |
} |
| 57 |
+ |
|
| 58 |
+ sort.Sort(osgraph.ByNodeID(markers)) |
|
| 59 |
+ if !strings.HasPrefix(markers[0].Message, "container ") {
|
|
| 60 |
+ t.Fatalf("message %q should state container", markers[0].Message)
|
|
| 61 |
+ } |
|
| 62 |
+ if !strings.HasPrefix(markers[1].Message, "container ") {
|
|
| 63 |
+ t.Fatalf("message %q should state container", markers[1].Message)
|
|
| 64 |
+ } |
|
| 65 |
+ if strings.HasPrefix(markers[2].Message, "container ") {
|
|
| 66 |
+ t.Fatalf("message %q should not state container", markers[2].Message)
|
|
| 67 |
+ } |
|
| 57 | 68 |
} |
| ... | ... |
@@ -274,7 +274,7 @@ func TestProjectStatus(t *testing.T) {
|
| 274 | 274 |
ErrFn: func(err error) bool { return err == nil },
|
| 275 | 275 |
Contains: []string{
|
| 276 | 276 |
`container "ruby-helloworld" in pod/frontend-app-1-bjwh8 has restarted 8 times`, |
| 277 |
- `container "gitlab-ce" in pod/gitlab-ce-1-lc411 is crash-looping`, |
|
| 277 |
+ `pod/gitlab-ce-1-lc411 is crash-looping`, |
|
| 278 | 278 |
`oc logs -p gitlab-ce-1-lc411 -c gitlab-ce`, // verifies we print the log command |
| 279 | 279 |
`policycommand example default`, // verifies that we print the help command |
| 280 | 280 |
}, |