Merge pull request #122038 from lowang-bh/fixPodshow
show pod Status as phase Failed or Succeeded if it has deletionTimestamp Kubernetes-commit: b669abc18163a703d1db5ae3c32fd2faff1694b3
This commit is contained in:
commit
ce7ca659e3
2
go.mod
2
go.mod
|
|
@ -32,7 +32,7 @@ require (
|
|||
k8s.io/api v0.0.0-20240611003639-590e50434bf1
|
||||
k8s.io/apimachinery v0.0.0-20240611003333-1a6a62ad18e9
|
||||
k8s.io/cli-runtime v0.0.0-20240611011948-8b261b067466
|
||||
k8s.io/client-go v0.0.0-20240611004119-911684686f22
|
||||
k8s.io/client-go v0.0.0-20240611082225-03443e7ede0e
|
||||
k8s.io/component-base v0.0.0-20240611005304-e4e29391883e
|
||||
k8s.io/component-helpers v0.0.0-20240611005446-043edfa5ae00
|
||||
k8s.io/klog/v2 v2.120.1
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -283,8 +283,8 @@ k8s.io/apimachinery v0.0.0-20240611003333-1a6a62ad18e9 h1:uEYcGyr07zLyUWoDL38erR
|
|||
k8s.io/apimachinery v0.0.0-20240611003333-1a6a62ad18e9/go.mod h1:3nAExNh3CrzC6eKT9a32j/rv+uJ8Zod87oOmgUjZNAY=
|
||||
k8s.io/cli-runtime v0.0.0-20240611011948-8b261b067466 h1:Ov7uW+LTmIt5IOAJzJ1HNiabwirtxxOhshzrsQmZQZg=
|
||||
k8s.io/cli-runtime v0.0.0-20240611011948-8b261b067466/go.mod h1:6U0kAMmtb2fPtCA232awVh1xpHogO4ZeqmLhjaunylw=
|
||||
k8s.io/client-go v0.0.0-20240611004119-911684686f22 h1:FEnPfVxr7ceNnA4clyhktWgs4HwRMlDZsUmfGGDFE9Q=
|
||||
k8s.io/client-go v0.0.0-20240611004119-911684686f22/go.mod h1:b+pw4KhbMeVhXpDIGvHd7EZRNwncNsJ2bdukPsB5dCc=
|
||||
k8s.io/client-go v0.0.0-20240611082225-03443e7ede0e h1:4/fBa74JXsX4qdGyj9KuXNtQTbsy0iCQv0pP3fWLHxg=
|
||||
k8s.io/client-go v0.0.0-20240611082225-03443e7ede0e/go.mod h1:b+pw4KhbMeVhXpDIGvHd7EZRNwncNsJ2bdukPsB5dCc=
|
||||
k8s.io/component-base v0.0.0-20240611005304-e4e29391883e h1:01PCd3dAM82OYe1j4jdCiOHZU3otF7acPD0+2SMgsSA=
|
||||
k8s.io/component-base v0.0.0-20240611005304-e4e29391883e/go.mod h1:5dgaBdnhsQFyIcJl45Rckw9rEXaHcezofXAL/GTk4YU=
|
||||
k8s.io/component-helpers v0.0.0-20240611005446-043edfa5ae00 h1:ZCr6jtEbLir+jAI+kyD8OENzUK+0CgcbXAzXKb+CC54=
|
||||
|
|
|
|||
|
|
@ -811,7 +811,7 @@ func describePod(pod *corev1.Pod, events *corev1.EventList) (string, error) {
|
|||
}
|
||||
printLabelsMultiline(w, "Labels", pod.Labels)
|
||||
printAnnotationsMultiline(w, "Annotations", pod.Annotations)
|
||||
if pod.DeletionTimestamp != nil {
|
||||
if pod.DeletionTimestamp != nil && pod.Status.Phase != corev1.PodFailed && pod.Status.Phase != corev1.PodSucceeded {
|
||||
w.Write(LEVEL_0, "Status:\tTerminating (lasts %s)\n", translateTimestampSince(*pod.DeletionTimestamp))
|
||||
w.Write(LEVEL_0, "Termination Grace Period:\t%ds\n", *pod.DeletionGracePeriodSeconds)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func TestDescribePod(t *testing.T) {
|
|||
gracePeriod := int64(1234)
|
||||
condition1 := corev1.PodConditionType("condition1")
|
||||
condition2 := corev1.PodConditionType("condition2")
|
||||
fake := fake.NewSimpleClientset(&corev1.Pod{
|
||||
runningPod := corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Namespace: "foo",
|
||||
|
|
@ -85,6 +85,7 @@ func TestDescribePod(t *testing.T) {
|
|||
},
|
||||
},
|
||||
Status: corev1.PodStatus{
|
||||
Phase: corev1.PodRunning,
|
||||
Conditions: []corev1.PodCondition{
|
||||
{
|
||||
Type: condition1,
|
||||
|
|
@ -92,18 +93,46 @@ func TestDescribePod(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
||||
d := PodDescriber{c}
|
||||
out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !strings.Contains(out, "bar") || !strings.Contains(out, "Status:") {
|
||||
t.Errorf("unexpected out: %s", out)
|
||||
tests := []struct {
|
||||
name string
|
||||
namespace string
|
||||
phase corev1.PodPhase
|
||||
wantOutput []string
|
||||
}{
|
||||
{
|
||||
name: "foo", namespace: "bar", phase: "Running",
|
||||
wantOutput: []string{"bar", "Status:", "Terminating (lasts 10y)", "Termination Grace Period", "1234s"},
|
||||
},
|
||||
{
|
||||
name: "pod1", namespace: "ns1", phase: "Pending",
|
||||
wantOutput: []string{"pod1", "ns1", "Terminating (lasts 10y)", "Termination Grace Period", "1234s"},
|
||||
},
|
||||
{
|
||||
name: "pod2", namespace: "ns2", phase: "Succeeded",
|
||||
wantOutput: []string{"pod2", "ns2", "Succeeded"},
|
||||
},
|
||||
{
|
||||
name: "pod3", namespace: "ns3", phase: "Failed",
|
||||
wantOutput: []string{"pod3", "ns3", "Failed"},
|
||||
},
|
||||
}
|
||||
if !strings.Contains(out, "Terminating (lasts 10y)") || !strings.Contains(out, "1234s") {
|
||||
t.Errorf("unexpected out: %s", out)
|
||||
|
||||
for i, test := range tests {
|
||||
pod := runningPod.DeepCopy()
|
||||
pod.Name, pod.Namespace, pod.Status.Phase = test.name, test.namespace, test.phase
|
||||
fake := fake.NewSimpleClientset(pod)
|
||||
c := &describeClient{T: t, Namespace: pod.Namespace, Interface: fake}
|
||||
d := PodDescriber{c}
|
||||
out, err := d.Describe(pod.Namespace, pod.Name, DescriberSettings{ShowEvents: true})
|
||||
if err != nil {
|
||||
t.Errorf("case %d: unexpected error: %v", i, err)
|
||||
}
|
||||
for _, wantStr := range test.wantOutput {
|
||||
if !strings.Contains(out, wantStr) {
|
||||
t.Errorf("case %d didn't contain want(%s): unexpected out:\n%s", i, wantStr, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue