update
This commit is contained in:
1 parent
0690285147
commit
5618cd2738
154 files changed
+5021
-3161
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
k8sclient "ezops/pkg/kubernetesclient"
|
||||
)
|
||||
|
||||
func TestPodDiagnosisStatusDetectsWaitingReason(t *testing.T) {
|
||||
pod := k8sclient.PodItem{
|
||||
Status: k8sclient.PodStatus{
|
||||
Phase: "Pending",
|
||||
ContainerStatuses: []k8sclient.ContainerStatus{{
|
||||
Name: "app",
|
||||
State: k8sclient.ContainerStatusState{Waiting: &k8sclient.ContainerStateWaiting{
|
||||
Reason: "ImagePullBackOff", Message: "Back-off pulling image",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
}
|
||||
status, reason, restarts, messages := podDiagnosisStatus(pod)
|
||||
if status != "ImagePullBackOff" || reason != "ImagePullBackOff" {
|
||||
t.Fatalf("unexpected status=%s reason=%s", status, reason)
|
||||
}
|
||||
if restarts != 0 {
|
||||
t.Fatalf("unexpected restarts=%d", restarts)
|
||||
}
|
||||
if len(messages) != 1 {
|
||||
t.Fatalf("expected waiting message, got %v", messages)
|
||||
}
|
||||
if !isAbnormalPod(status, reason, restarts) {
|
||||
t.Fatal("ImagePullBackOff should be abnormal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPodDiagnosisStatusDetectsOOMKilled(t *testing.T) {
|
||||
pod := k8sclient.PodItem{
|
||||
Status: k8sclient.PodStatus{
|
||||
Phase: "Running",
|
||||
ContainerStatuses: []k8sclient.ContainerStatus{{
|
||||
Name: "app", Ready: true, RestartCount: 3,
|
||||
LastState: k8sclient.ContainerStatusState{Terminated: &k8sclient.ContainerStateTerminated{
|
||||
Reason: "OOMKilled", ExitCode: 137,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
}
|
||||
status, reason, restarts, _ := podDiagnosisStatus(pod)
|
||||
if status != "Running" || reason != "OOMKilled" || restarts != 3 {
|
||||
t.Fatalf("unexpected status=%s reason=%s restarts=%d", status, reason, restarts)
|
||||
}
|
||||
if !isAbnormalPod(status, reason, restarts) {
|
||||
t.Fatal("OOMKilled should be abnormal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsAbnormalPodByRestartThreshold(t *testing.T) {
|
||||
if !isAbnormalPod("Running", "Running", 10) {
|
||||
t.Fatal("high restart pod should be abnormal")
|
||||
}
|
||||
if isAbnormalPod("Running", "Running", 2) {
|
||||
t.Fatal("healthy running pod should not be abnormal")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user