mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #124677 from HirazawaUi/add-const-ContainerStatusUnknown
kubelet: Use constant replace same value variables of the ContainerStateTerminated Reason field
This commit is contained in:
commit
009a291573
@ -274,6 +274,9 @@ const (
|
||||
ContainerStateUnknown State = "unknown"
|
||||
)
|
||||
|
||||
// ContainerReasonStatusUnknown indicates a container the status of the container cannot be determined.
|
||||
const ContainerReasonStatusUnknown string = "ContainerStatusUnknown"
|
||||
|
||||
// Container provides the runtime information for a container, such as ID, hash,
|
||||
// state of the container.
|
||||
type Container struct {
|
||||
|
@ -2028,7 +2028,7 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
|
||||
// twice. "container never ran" is different than "container ran and failed". This is handled differently in the kubelet
|
||||
// and it is handled differently in higher order logic like crashloop detection and handling
|
||||
status.State.Terminated = &v1.ContainerStateTerminated{
|
||||
Reason: "ContainerStatusUnknown",
|
||||
Reason: kubecontainer.ContainerReasonStatusUnknown,
|
||||
Message: "The container could not be located when the pod was terminated",
|
||||
ExitCode: 137, // this code indicates an error
|
||||
}
|
||||
@ -2255,7 +2255,7 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
|
||||
// https://github.com/kubernetes/kubernetes/blob/90c9f7b3e198e82a756a68ffeac978a00d606e55/pkg/kubelet/kubelet_pods.go#L1440-L1445
|
||||
// This prevents the pod from becoming pending
|
||||
status.LastTerminationState.Terminated = &v1.ContainerStateTerminated{
|
||||
Reason: "ContainerStatusUnknown",
|
||||
Reason: kubecontainer.ContainerReasonStatusUnknown,
|
||||
Message: "The container could not be located when the pod was deleted. The container used to be Running",
|
||||
ExitCode: 137,
|
||||
}
|
||||
|
@ -2154,7 +2154,7 @@ func waitingWithLastTerminationUnknown(cName string, restartCount int32) v1.Cont
|
||||
},
|
||||
LastTerminationState: v1.ContainerState{
|
||||
Terminated: &v1.ContainerStateTerminated{
|
||||
Reason: "ContainerStatusUnknown",
|
||||
Reason: kubecontainer.ContainerReasonStatusUnknown,
|
||||
Message: "The container could not be located when the pod was deleted. The container used to be Running",
|
||||
ExitCode: 137,
|
||||
},
|
||||
|
@ -2135,7 +2135,7 @@ func TestGenerateAPIPodStatusWithReasonCache(t *testing.T) {
|
||||
"unknown": {Terminated: &v1.ContainerStateTerminated{
|
||||
ExitCode: 137,
|
||||
Message: "The container could not be located when the pod was terminated",
|
||||
Reason: "ContainerStatusUnknown",
|
||||
Reason: kubecontainer.ContainerReasonStatusUnknown,
|
||||
}},
|
||||
},
|
||||
expectedLastTerminationState: map[string]v1.ContainerState{
|
||||
|
@ -446,7 +446,7 @@ func (m *manager) TerminatePod(pod *v1.Pod) {
|
||||
}
|
||||
status.ContainerStatuses[i].State = v1.ContainerState{
|
||||
Terminated: &v1.ContainerStateTerminated{
|
||||
Reason: "ContainerStatusUnknown",
|
||||
Reason: kubecontainer.ContainerReasonStatusUnknown,
|
||||
Message: "The container could not be located when the pod was terminated",
|
||||
ExitCode: 137,
|
||||
},
|
||||
@ -462,7 +462,7 @@ func (m *manager) TerminatePod(pod *v1.Pod) {
|
||||
}
|
||||
status.InitContainerStatuses[i].State = v1.ContainerState{
|
||||
Terminated: &v1.ContainerStateTerminated{
|
||||
Reason: "ContainerStatusUnknown",
|
||||
Reason: kubecontainer.ContainerReasonStatusUnknown,
|
||||
Message: "The container could not be located when the pod was terminated",
|
||||
ExitCode: 137,
|
||||
},
|
||||
|
@ -638,7 +638,7 @@ func TestTerminatePod(t *testing.T) {
|
||||
assert.False(t, newStatus.InitContainerStatuses[i].State.Terminated == nil, "expected init containers to be terminated")
|
||||
}
|
||||
|
||||
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: "ContainerStatusUnknown", Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
|
||||
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: kubecontainer.ContainerReasonStatusUnknown, Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
|
||||
if !reflect.DeepEqual(newStatus.InitContainerStatuses[0].State, expectUnknownState) {
|
||||
t.Errorf("terminated container state not defaulted: %s", cmp.Diff(newStatus.InitContainerStatuses[0].State, expectUnknownState))
|
||||
}
|
||||
@ -723,7 +723,7 @@ func TestTerminatePodWaiting(t *testing.T) {
|
||||
assert.False(t, container.State.Waiting == nil, "expected init containers to be waiting")
|
||||
}
|
||||
|
||||
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: "ContainerStatusUnknown", Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
|
||||
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: kubecontainer.ContainerReasonStatusUnknown, Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
|
||||
if !reflect.DeepEqual(newStatus.InitContainerStatuses[0].State, expectUnknownState) {
|
||||
t.Errorf("terminated container state not defaulted: %s", cmp.Diff(newStatus.InitContainerStatuses[0].State, expectUnknownState))
|
||||
}
|
||||
@ -772,7 +772,7 @@ func TestTerminatePod_DefaultUnknownStatus(t *testing.T) {
|
||||
if state.Terminated == nil || state.Running != nil || state.Waiting != nil {
|
||||
t.Fatalf("unexpected state: %#v", state)
|
||||
}
|
||||
if state.Terminated.ExitCode != 137 || state.Terminated.Reason != "ContainerStatusUnknown" || len(state.Terminated.Message) == 0 {
|
||||
if state.Terminated.ExitCode != 137 || state.Terminated.Reason != kubecontainer.ContainerReasonStatusUnknown || len(state.Terminated.Message) == 0 {
|
||||
t.Fatalf("unexpected terminated state: %#v", state.Terminated)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user