Skip to content

Commit 7a4531c

Browse files
committed
add ContainerStatusUnknown constant
1 parent bb838fd commit 7a4531c

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

pkg/kubelet/container/runtime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ const (
274274
ContainerStateUnknown State = "unknown"
275275
)
276276

277+
// ContainerReasonStatusUnknown indicates a container the status of the container cannot be determined.
278+
const ContainerReasonStatusUnknown string = "ContainerStatusUnknown"
279+
277280
// Container provides the runtime information for a container, such as ID, hash,
278281
// state of the container.
279282
type Container struct {

pkg/kubelet/kubelet_pods.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
20162016
// twice. "container never ran" is different than "container ran and failed". This is handled differently in the kubelet
20172017
// and it is handled differently in higher order logic like crashloop detection and handling
20182018
status.State.Terminated = &v1.ContainerStateTerminated{
2019-
Reason: "ContainerStatusUnknown",
2019+
Reason: kubecontainer.ContainerReasonStatusUnknown,
20202020
Message: "The container could not be located when the pod was terminated",
20212021
ExitCode: 137, // this code indicates an error
20222022
}
@@ -2226,7 +2226,7 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
22262226
// https://github.com/kubernetes/kubernetes/blob/90c9f7b3e198e82a756a68ffeac978a00d606e55/pkg/kubelet/kubelet_pods.go#L1440-L1445
22272227
// This prevents the pod from becoming pending
22282228
status.LastTerminationState.Terminated = &v1.ContainerStateTerminated{
2229-
Reason: "ContainerStatusUnknown",
2229+
Reason: kubecontainer.ContainerReasonStatusUnknown,
22302230
Message: "The container could not be located when the pod was deleted. The container used to be Running",
22312231
ExitCode: 137,
22322232
}

pkg/kubelet/kubelet_pods_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,7 @@ func waitingWithLastTerminationUnknown(cName string, restartCount int32) v1.Cont
21542154
},
21552155
LastTerminationState: v1.ContainerState{
21562156
Terminated: &v1.ContainerStateTerminated{
2157-
Reason: "ContainerStatusUnknown",
2157+
Reason: kubecontainer.ContainerReasonStatusUnknown,
21582158
Message: "The container could not be located when the pod was deleted. The container used to be Running",
21592159
ExitCode: 137,
21602160
},

pkg/kubelet/kubelet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ func TestGenerateAPIPodStatusWithReasonCache(t *testing.T) {
21342134
"unknown": {Terminated: &v1.ContainerStateTerminated{
21352135
ExitCode: 137,
21362136
Message: "The container could not be located when the pod was terminated",
2137-
Reason: "ContainerStatusUnknown",
2137+
Reason: kubecontainer.ContainerReasonStatusUnknown,
21382138
}},
21392139
},
21402140
expectedLastTerminationState: map[string]v1.ContainerState{

pkg/kubelet/status/status_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func (m *manager) TerminatePod(pod *v1.Pod) {
446446
}
447447
status.ContainerStatuses[i].State = v1.ContainerState{
448448
Terminated: &v1.ContainerStateTerminated{
449-
Reason: "ContainerStatusUnknown",
449+
Reason: kubecontainer.ContainerReasonStatusUnknown,
450450
Message: "The container could not be located when the pod was terminated",
451451
ExitCode: 137,
452452
},
@@ -462,7 +462,7 @@ func (m *manager) TerminatePod(pod *v1.Pod) {
462462
}
463463
status.InitContainerStatuses[i].State = v1.ContainerState{
464464
Terminated: &v1.ContainerStateTerminated{
465-
Reason: "ContainerStatusUnknown",
465+
Reason: kubecontainer.ContainerReasonStatusUnknown,
466466
Message: "The container could not be located when the pod was terminated",
467467
ExitCode: 137,
468468
},

pkg/kubelet/status/status_manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ func TestTerminatePod(t *testing.T) {
638638
assert.False(t, newStatus.InitContainerStatuses[i].State.Terminated == nil, "expected init containers to be terminated")
639639
}
640640

641-
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: "ContainerStatusUnknown", Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
641+
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: kubecontainer.ContainerReasonStatusUnknown, Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
642642
if !reflect.DeepEqual(newStatus.InitContainerStatuses[0].State, expectUnknownState) {
643643
t.Errorf("terminated container state not defaulted: %s", cmp.Diff(newStatus.InitContainerStatuses[0].State, expectUnknownState))
644644
}
@@ -723,7 +723,7 @@ func TestTerminatePodWaiting(t *testing.T) {
723723
assert.False(t, container.State.Waiting == nil, "expected init containers to be waiting")
724724
}
725725

726-
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: "ContainerStatusUnknown", Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
726+
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: kubecontainer.ContainerReasonStatusUnknown, Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
727727
if !reflect.DeepEqual(newStatus.InitContainerStatuses[0].State, expectUnknownState) {
728728
t.Errorf("terminated container state not defaulted: %s", cmp.Diff(newStatus.InitContainerStatuses[0].State, expectUnknownState))
729729
}
@@ -772,7 +772,7 @@ func TestTerminatePod_DefaultUnknownStatus(t *testing.T) {
772772
if state.Terminated == nil || state.Running != nil || state.Waiting != nil {
773773
t.Fatalf("unexpected state: %#v", state)
774774
}
775-
if state.Terminated.ExitCode != 137 || state.Terminated.Reason != "ContainerStatusUnknown" || len(state.Terminated.Message) == 0 {
775+
if state.Terminated.ExitCode != 137 || state.Terminated.Reason != kubecontainer.ContainerReasonStatusUnknown || len(state.Terminated.Message) == 0 {
776776
t.Fatalf("unexpected terminated state: %#v", state.Terminated)
777777
}
778778
}

0 commit comments

Comments
 (0)