Skip to content

Commit

Permalink
Deck reports init container failure
Browse files Browse the repository at this point in the history
  • Loading branch information
chaodaiG committed Feb 11, 2021
1 parent 2c107b0 commit 5d68278
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
21 changes: 19 additions & 2 deletions prow/spyglass/lenses/metadata/lens.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,25 @@ func hintFromPodInfo(buf []byte) string {
}
}

// We've got nothing.
return ""
// There are cases where initContainers failed to start
var msg string
for _, ic := range report.Pod.Status.InitContainerStatuses {
if ic.Ready {
continue
}
// Init container not ready by the time this job failed
// The 3 different states should be mutually exclusive, if it happens
// that there are more than one, use the most severe one
if state := ic.State.Terminated; state != nil {
msg = fmt.Sprintf("state: terminated, reason: %q, message: %q", state.Reason, state.Message)
} else if state := ic.State.Waiting; state != nil {
msg = fmt.Sprintf("state: waiting, reason: %q, message: %q", state.Reason, state.Message)
} else if state := ic.State.Running; state != nil { // This shouldn't happen at all, just in case.
logrus.WithField("pod", report.Pod.Name).WithField("container", ic.Name).Warning("Init container is running but not ready")
}
msg = fmt.Sprintf("Init container %s not ready: (%s)", ic.Name, msg)
}
return msg
}

func hintFromProwJob(buf []byte) (string, bool) {
Expand Down
46 changes: 46 additions & 0 deletions prow/spyglass/lenses/metadata/lens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,52 @@ func TestHintFromPodInfo(t *testing.T) {
},
},
},
{
name: "init container failed to start",
expected: "Init container initupload not ready: (state: terminated, reason: \"Error\", message: \"failed fetching oauth2 token\")",
info: k8sreporter.PodReport{
Pod: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "8ef160fc-46b6-11ea-a907-1a9873703b03",
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "test",
Image: "gcr.io/k8s-testimages/kubekins-e2e:v20200428-06f6e3b-master",
},
},
},
Status: v1.PodStatus{
Phase: v1.PodPending,
InitContainerStatuses: []v1.ContainerStatus{
{
Name: "initupload",
Ready: false,
State: v1.ContainerState{
Terminated: &v1.ContainerStateTerminated{
Reason: "Error",
Message: "failed fetching oauth2 token",
},
},
},
},
ContainerStatuses: []v1.ContainerStatus{
{
Name: "test",
Image: "gcr.io/k8s-testimages/kubekins-e2e:v20200428-06f6e3b-master",
Ready: false,
State: v1.ContainerState{
Waiting: &v1.ContainerStateWaiting{
Reason: "PodInitializing",
},
},
},
},
},
},
},
},
}

for _, tc := range tests {
Expand Down
1 change: 0 additions & 1 deletion prow/test/integration/fakeghserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ go_library(
"//prow/interrupts:go_default_library",
"//prow/logrusutil:go_default_library",
"//prow/pjutil:go_default_library",
"@com_github_google_go_github//github:go_default_library",
"@com_github_gorilla_mux//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
Expand Down

0 comments on commit 5d68278

Please sign in to comment.