From 960d7fbf094b5885890dffe4cd68fc6a14416f16 Mon Sep 17 00:00:00 2001 From: reinka Date: Fri, 2 Feb 2024 20:53:27 +0100 Subject: [PATCH] add admission tests --- pkg/kubelet/eviction/eviction_manager_test.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/kubelet/eviction/eviction_manager_test.go b/pkg/kubelet/eviction/eviction_manager_test.go index bf7340c9ebc..336b8e69bde 100644 --- a/pkg/kubelet/eviction/eviction_manager_test.go +++ b/pkg/kubelet/eviction/eviction_manager_test.go @@ -986,6 +986,9 @@ func TestPIDPressure(t *testing.T) { thresholdsFirstObservedAt: thresholdsObservedAt{}, } + // create a best effort pod to test admission + podToAdmit, _ := podMaker("pod-to-admit", defaultPriority, 50) + // synchronize _, err := manager.synchronize(diskInfoProvider, activePodsFunc) @@ -998,6 +1001,11 @@ func TestPIDPressure(t *testing.T) { t.Fatalf("Manager should not report disk pressure") } + // try to admit our pod (should succeed) + if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: podToAdmit}); !result.Admit { + t.Fatalf("Admit pod: %v, expected: %v, actual: %v", podToAdmit, true, result.Admit) + } + // induce soft threshold for PID pressure fakeClock.Step(1 * time.Minute) summaryProvider.result = summaryStatsMaker("2000", "700", podStats) @@ -1087,6 +1095,11 @@ func TestPIDPressure(t *testing.T) { t.Errorf("Manager chose to kill pod with incorrect grace period. Expected: %d, actual: %d", 0, observedGracePeriod) } + // try to admit our pod (should fail) + if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: podToAdmit}); result.Admit { + t.Fatalf("Admit pod: %v, expected: %v, actual: %v", podToAdmit, false, result.Admit) + } + // reduce PID pressure fakeClock.Step(1 * time.Minute) summaryProvider.result = summaryStatsMaker("2000", "300", podStats) @@ -1107,6 +1120,11 @@ func TestPIDPressure(t *testing.T) { t.Errorf("Manager chose to kill pod: %v when no pod should have been killed", podKiller.pod.Name) } + // try to admit our pod (should fail) + if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: podToAdmit}); result.Admit { + t.Fatalf("Admit pod: %v, expected: %v, actual: %v", podToAdmit, false, result.Admit) + } + // move the clock past the transition period fakeClock.Step(5 * time.Minute) summaryProvider.result = summaryStatsMaker("2000", "300", podStats) @@ -1125,6 +1143,11 @@ func TestPIDPressure(t *testing.T) { if podKiller.pod != nil { t.Errorf("Manager chose to kill pod: %v when no pod should have been killed", podKiller.pod.Name) } + + // try to admit our pod (should succeed) + if result := manager.Admit(&lifecycle.PodAdmitAttributes{Pod: podToAdmit}); !result.Admit { + t.Fatalf("Admit pod: %v, expected: %v, actual: %v", podToAdmit, true, result.Admit) + } } func TestAdmitUnderNodeConditions(t *testing.T) {